HOW TO CATCH ALL EXCEPTIONS IN C# USING TRY AND CATCH?

jayprakash sharma

Total Post:117

Points:821
Posted by  jayprakash sharma
C#
 1055  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. Pravesh Singh

    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.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!