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
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