Answer the question
In order to leave comments, you need to log in
SystemException specific?
Hello everyone, I started to study exceptions. I study video course.
There is such an example:
class Program
{
static void Main()
{
int a = 1, n = 2;
try
{
// Попытка деления на ноль.
a = a / (2 - n);
Console.WriteLine("a = {0}", a);
}
catch (Exception e)
{
Console.WriteLine("Обработка исключения.");
Console.WriteLine(e.Message);
}
// Delay.
Console.ReadKey();
}
}
a = a / (2 - n);
catch (Exception e)
catch (DevideByZeroException e)
catch ( ArithmeticException e)
Answer the question
In order to leave comments, you need to log in
About the first question. No, all exceptions are not cast to a specific type at compile time. That is, a DevideByZeroException exception is thrown, and then, sequentially, in the catch blocks, the type to which this exception can be cast is searched.
For example, you can perform different actions on different exceptions. Code that catches an exception of type Exception will be executed only if the thrown exception cannot be cast to the types described earlier
try
{
//Code
}
catch ( DivideByZeroException ex )
{
}
catch ( ArithmeticException ex )
{
}
catch ( Exception ex )
{
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question