Advertise with us

How to catch all exceptions in c# using try and catch?

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 {}

?

Last updated:9/24/2013 7:43:34 AM

1 Answers

Pravesh Singh
Pravesh Singh

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.

Last updated:9/24/2013 7:43:34 AM

Answer