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

Total Post:117

Points:821
C#
 1326  View(s)
Ratings:
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 {}

?

  1. Post:412

    Points:2888
    Re: How to catch all exceptions in c# using try and catch?

    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.

      Modified On Mar-31-2018 01:45:15 AM

Answer