I was wondering if I could catch all the exceptions within a function, for that I would consider the following example.
My question is mainly if I can catch dividebyzeroexception within the definition of the function and not from outside.
static int division(int a, int b)
{
try
{
if (a == 5)
{
throw new miexcep();
}
return a / b;
}
catch (miexcep)
{
Console.WriteLine("A no puede ser 5!!");
}
return a / b;
}
try
{
division(5, 0);
}
catch (DivideByZeroException)
{
Console.WriteLine("B no puede ser 0");
}