Understanding exception handler example in SDK

G

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top