Home > DeveloperSection > Forums > How to catch all exceptions in c# using try and catch?
jayprakash sharma
jayprakash sharma

Total Post:117

Points:821
Posted on    September-24-2013 4:37 AM

 C#
Ratings:


 1 Reply(s)
 781  View(s)
Rate this:

I want to write some try and catch that catch any type or exception

try {

code....

}

catch (Exception ex){}

Or should it be

try {

code....

}

catch {}

?



Pravesh Singh

Total Post:411

Points:2881
Posted on    September-24-2013 7:43 AM

Hi JayPrakash,

Both ways are correct If you need to do something with Exception object in catch block than you should use

try {

code....

}             

catch (Exception ex){}

and than use ex in catch block.


Don't want to miss updates? Please click the below button!

Follow MindStick