How many catch Statement can be associated with single try statement?

 Posted by Ddd on 3/7/2011 | Category: C# Interview questions | Views: 3336 | Points: 40
Answer:

It can be 0 to as many.
try must be followed by catch or finally.

ex:
1)0 catch statement
try
{

}
finally
{

}


2) any number
try
{

}

catch
{

}
catch
{

}
finally
{

}


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Kishork80 on: 3/8/2011 | Points: 10
One interesting thing about the placement of the multiple catch blocks is that you place all specific exceptions that you want to catch first before placing generic ones. Because the Exception class is the base of all exception classes, it should always be placed last in a catch block so that any exception that is not caught in the previous catch blocks is always caught

Login to post response