Let's suppose we have such code:
int x = 0;
try
{
try
{
x /= x; // DivideByZeroException
}
finally
{
throw new OverflowException("foobar"); // how to pass thrown exception here
}
}
catch(Exception e)
{
System.Console.WriteLine(e.Message);
}
Is it possible to get thrown exception in finally and pass it as a second argument of OverflowException
?
UPD: guys, I do know how to work with catch
and I do know that it is weird practice to throw an exception from finally.
But the original quesition (which definitely has science nature, not practical) can we retrieve thrown exception in the finally?
Yes (then how)? No? That's all I wanted to see.