How to avoid propagation of exception

Hi,

I have code as following

function1()

{ .....

try

{ function2();}

catch (Exception ex1){}

finally{}

}

and function2 is

function2

{ .....

try

{ function2();}

catch (Exception ex2 ){}

finally{}

}

when ex2 happens , exception is propagated to function1 (caller) and ex1 is catched again.

How can I avoid that ex1 is catched and only be catched by ex2

Thanks



Answer this question

How to avoid propagation of exception

  • Dave Waterworth

    Caught exceptions are not rethrown automatically. But your example results in infinite recursion which causes the .NET runtime to throw a System.StackOverflowException that cannot be caught at all using try/catch as of .NET 2.0.
  • How to avoid propagation of exception