Hi,
Is it possible that a try block can have more than one catch block?
Try and catch block
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
SenthilkumarRank #387 · 6.5K reputationPosted Mar 11, 2012, 11:17 PM EDT
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.