Exforsys
+ Reply to Thread
Results 1 to 3 of 3

Generic Exception Handling

This is a discussion on Generic Exception Handling within the C Sharp forums, part of the Programming Talk category; I have written an exception in my C# code as below: catch(FileNotFoundException example) { Console.WriteLine(example.ToString()); } But the above would ...

  1. #1
    rachelle is offline Member Array
    Join Date
    Apr 2006
    Answers
    97

    Question Generic Exception Handling

    I have written an exception in my C# code as below:
    catch(FileNotFoundException example)
    {
    Console.WriteLine(example.ToString());
    }

    But the above would only catch exceptions when FileNotFoundException exception is thrown. I want to handle and catch other generic Exceptions also. How can I write exception for these?


  2. #2
    sammy is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    144
    The following would handle and catch other generic Exceptions
    catch (Exception e1)
    {
    .................
    ...................
    }
    In the catch block you can write code that does general error handling.
    finally
    {
    .................
    ...................

    }

    In the above finally clock you can write code so that the whatever written in finally block of code gets executed irrespective of before events.


  3. #3
    anandh_exforsys is offline Junior Member Array
    Join Date
    Oct 2007
    Answers
    1

    Exception handling

    hi,

    try
    {
    ...
    }

    catch(FileNotFoundException example)
    {
    Console.WriteLine(example.ToString());
    }

    catch(Exception e)
    {
    Console.WriteLine(example.ToString());
    }

    while doing this, if u got FileNotFoundException, the first catch block will execute, for any other exceptions, the generic exception catch block will execute...


    •    Sponsored Ads



Latest Article

Network Security Risk Assessment and Measurement

Read More...