Monday, March 3, 2008

Exception Handling of C#

_____________________________________________

Exception Handling of C#.

_____________________________________________

// Throw an exception
Exception up = new Exception("Something is really wrong.");
throw up; // ha ha

// Catch an exception
try {
y = 0;
x = 10 / y;
}
catch (Exception ex) { // Argument is optional, no "When" keyword
Console.WriteLine(ex.Message);
}
finally {
// Requires reference to the Microsoft.VisualBasic.dll
// assembly (pre .NET Framework v2.0)
Microsoft.VisualBasic.Interaction.Beep();
}

____________________________________________________________________

Note:Applicable for .net also asp.net.
____________________________________________________________________

No comments: