Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
if a try block having 4 catch blocks, can fire exception to entire catch block ?
Posted
Updated 1-Apr-19 19:41pm
Comments
Kenneth Haugland 8-Oct-12 10:26am    
Yes, its called nested try catch blocks. You should find lots of examples by a search on google.
bbirajdar 8-Oct-12 10:27am    
why not write a simple program and test it ? And BTW your question is not clear.. What do you mean by 'entire catch block' ?
Sergey Alexandrovich Kryukov 8-Oct-12 17:33pm    
Exceptions are thrown, not "fired". What is "entire" catch block? There is no such thing, and this is the key.
--SA

C#
try{
}
catch(ExceptionType1 ex1)
{
}
catch(ExceptionType2 ex2)
{
}
...
catch(Exception ex)
{
}

Given the above if none of the exception types match the the last exception handler will catch the exception.
 
Share this answer
 
Yes. its possible.

C#
try
{
    // Many types of exceptions can be thrown
}
catch (CustomException ce)
{
    ...
}
catch (AnotherCustomException ace)
{
    ...
}
catch (Exception ex)
{
    ...
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900