Answer: A throw statement is used to generate exception explicitly.
This throw statement is generally used in recording error in event log or sending an Email notification about the error.
Avoid using throw statement as it degrades the speed.
Example:
try
{
//Code that might generate error
}
catch(Exception error)
{
//Code that handle errors occurred in try block
throw; //Re throw of exception to add exception details in event log or sending email
}
//Code that handle errors occurred in try block
}
finally
{
//Code to dispose all allocated resources
}
Format2
try
{
//Code that might generate error
}
finally
{
//Code to dispose all allocated resources
}
Asked In: Many Interviews |
Alert Moderator