Describe exception handling in VB.NET.
- Exceptions or errors are unusual occurrences that happen within the logic of an application.
- The CLR has provided structured way to deal with exceptions using Try/Catch block.
Try:- It identifies a block of code for which particular exceptions is activated.
- It is followed by one or more catch blocks.
- It can be a compound statement.
Catch:- It catches an exception with an exception handler at the place in a program where you want to handle the problem.
- It indicates the catching of an exception.
- There are multiple Catch blocks permitted.
Finally:- It is used to execute a given set of statements, whether an exception is thrown or not thrown.
Syntax:try
{
//Statements
}
catch(ExceptionName e1)
{
//Error handling code
}
catch(ExceptionName e2)
{
//Error handling code
}
catch(ExceptionName eN)
{
//Error handling code
}
finally
{
//Statements to be executed
}
- Page and application error event handler is useful in cases where an exception is unexpected and does not occur within the bounds of a Try/Catch/Finally block.
- These exceptions are usually an indicator that something is substantially wrong with the application.