Understanding exception handler example in SDK

Discussion in 'ASP General' started by Guest, Dec 12, 2004.

  1. Guest

    Guest Guest

    I would appreciate some help in understanding the simple C# example relating
    to handling exceptions. This one relates to catching an error thrown by
    dividing number by zero.

    There are a few things I don't understand which I hope you can help me with:




    'using System;

    class ExceptionTestClass
    {
    public static void Main()
    {
    int x = 0;
    try
    {
    int y = 100/x;
    }
    catch (ArithmeticException e)
    {
    Console.WriteLine("ArithmeticException Handler: {0}",
    e.ToString());
    }
    catch (Exception e)
    {
    Console.WriteLine("Generic Exception Handler: {0}",
    e.ToString());
    }
    }
    }

    1. Is this class 'ExceptionTestClass a 'test' class for demonstration
    purposes...why is there is not a general Exception class one could call
    rather than the author's test?

    2. The variable 'ArithmeticException' and 'e' ...are these standard incoming
    variables from the excpection class or the author's exception class?

    3. Why does he have two 'catch' classes....does the second one check the
    first one to see if there was an error....

    4. What is the difference between the 'ArithmeticException Handler and the
    'Generic Exception Handler'.


    I realise these are proabably naive questions but I am just starting out.

    Thanks
    Jason
     
    Guest, Dec 12, 2004
    #1
    1. Advertising

  2. Guest

    Guest Guest

    Sorry wrong group!~!!


    <> wrote in message
    news:...
    >
    > I would appreciate some help in understanding the simple C# example

    relating
    > to handling exceptions. This one relates to catching an error thrown by
    > dividing number by zero.
    >
    > There are a few things I don't understand which I hope you can help me

    with:
    >
    >
    >
    >
    > 'using System;
    >
    > class ExceptionTestClass
    > {
    > public static void Main()
    > {
    > int x = 0;
    > try
    > {
    > int y = 100/x;
    > }
    > catch (ArithmeticException e)
    > {
    > Console.WriteLine("ArithmeticException Handler: {0}",
    > e.ToString());
    > }
    > catch (Exception e)
    > {
    > Console.WriteLine("Generic Exception Handler: {0}",
    > e.ToString());
    > }
    > }
    > }
    >
    > 1. Is this class 'ExceptionTestClass a 'test' class for demonstration
    > purposes...why is there is not a general Exception class one could call
    > rather than the author's test?
    >
    > 2. The variable 'ArithmeticException' and 'e' ...are these standard

    incoming
    > variables from the excpection class or the author's exception class?
    >
    > 3. Why does he have two 'catch' classes....does the second one check the
    > first one to see if there was an error....
    >
    > 4. What is the difference between the 'ArithmeticException Handler and the
    > 'Generic Exception Handler'.
    >
    >
    > I realise these are proabably naive questions but I am just starting out.
    >
    > Thanks
    > Jason
    >
    >
     
    Guest, Dec 12, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shruds
    Replies:
    1
    Views:
    933
    John C. Bollinger
    Jan 27, 2006
  2. Todd A. Anderson
    Replies:
    1
    Views:
    632
    Jack Klein
    Nov 3, 2004
  3. slyraymond
    Replies:
    5
    Views:
    286
    Mark Lutz
    Apr 26, 2004
  4. Replies:
    1
    Views:
    750
    Damien
    Feb 22, 2007
  5. Replies:
    0
    Views:
    375
Loading...

Share This Page