I have the following code in the 'main' method:
static void Main(string[] args)
{
try
{
int a = 0;
int b = 5;
b /= a;
}
catch (MyException ex)
{
Console.WriteLine(ex.Message)
}
}
And MyException class is as the following:
public class MyException : Exception
{
public MyException()
{
}
}
The program breaks on b /= a;
whereas I'm expecting it to go to the catch
command.
If I replace MyException
with Exception
, the exception is caught and the program doesn't break.
How can I catch a custom exception?