using System; class RethrowApp { static public void Main() { Rethrow rethrow = new Rethrow(); try { rethrow.Foo(); } catch(Exception e) { Console.WriteLine(e.Message); } } public void Foo() { try { Bar(); } catch(Exception) { // Handle error. throw; } } public void Bar() { throw new Exception("thrown by Rethrow.Bar"); } }
In this example, Main calls Foo, which calls Bar. Bar throws an exception that Foo catches. Foo at this point does some preprocessing and then rethrows the exception back up the call stack to Main by using the throw keyword.
by
updated