checked block is used to make sure if overflow happens, an exception is thrown. For example,
The below code throws overflow exception which is fine.
checked
{
int a = 123456;
int b = 123456;
Console.WriteLine(a * b);
}
But if I call a method inside the checked block, and the method in turn has code which is throwing overflow exception, checked block doesn't seem to detect that. Is it possible to detect these as well.
checked
{
int a = 123456;
int b = 123456;
Console.WriteLine(Mul(a, b));
}
public int Mul(int a, int b)
{
return a * b;
}