Hi,
Is it possible that a try block can have more than one catch block?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
SenthilkumarPosted Mar 12, 2012, 3:17 AM
Yes... You can use any number of catch block along with the try in C#.
But the Exception class is super class. It should always come last in the sequence.
The Catch and Finally block is optional block in C#.
The catch block can be written without any exception class mentioned.
For example, it should be like the following.
try
{
//code here
}
catch(FileNotFoundException fEx)
{
}
catch(Exception Ex)
{
}
I have written a very good article along with lot of examples. Please refer the following.
http://www.c-sharpcorner.com/uploadfile/skumaar_mca/exception-handling-in-C-Sharp/
If it is useful then please mark it as Accepted Answer.