I am not sure if what I am trying to do is even possible, but I figure there must be some work around for it. Assume two routines; routine A and routine B. Both routines A, and B have their own try-catch statements. Routine A will call routine B (shown below), and if routine B encounters some error, routine A will be notified of it.
Here is my example:
// Routine A
private void button13_Click(object sender, EventArgs e)
{
try
{
somevoid();
}
catch(Exception ex)
{
Console.WriteLine(ex.message); // Never makes it here ...
}
}
// Routine B
private void somevoid()
{
try
{
int i = 1;
int z = 0;
int g = i / z;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
I am not sure what you want to achieve, but it seems, you need to catch the exception in both try catch blocks. If so, change your code as follows: