Where will the control flow if an exception occurs inside a try block ?

 Posted by Bharathi Cherukuri on 7/25/2012 | Category: ASP.NET Interview questions | Views: 2671 | Points: 40
Answer:

If an exception occurs inside a try block, then the control flow passes immediately to the next catch statement. When control flow passes to a catch block, the statements contained in the catch block are processed to handle the exception.

Example:

int SafeDivision(int x, int y)
{
try
{
return (x / y);
}
catch (System.DivideByZeroException dbz)
{
System.Console.WriteLine("Division by zero attempted!");
return 0;
}
}


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response