Friday, April 30, 2010

What is an Exception, how do you achieve Exception Handling in .NET?

1 comment:

Jasmine said...

"Exception is a runtime error which arises because of abnormal conditions in a sequence."
The exceptions are anomalies that occur during the execution of a program.The System.Exception is the super class of exception.
Exception handling is an in built mechanism in .NET framework to detect and handle runtime errors. The .NET framework contains lots of standard exceptions.
Exception handling provides uniform, structured and type-safe handling errors.
C# provides three keywords try, catch and finally to do exception handling. The try encloses the statements that might throw an exception whereas catch handles exception if one exists. The finally can be used for doing any clean up process.
The general form of try-catch-finally in c# is shown below:

try
{
// Statements which can cause an exception
}
catch(Type x)
{
// Statements for handling the exception
}
finally
{
// Any Cleanup Code
}