CSharp examples for Custom Type:Exception
Stack unwinding and Exception class properties.
using System;//from w ww . j a v a2s .c om class Properties { static void Main() { try { Method1(); } catch (Exception exceptionParameter) { Console.WriteLine("exceptionParameter.ToString: \n" + exceptionParameter); Console.WriteLine("\nexceptionParameter.Message: \n" + exceptionParameter.Message); Console.WriteLine("\nexceptionParameter.StackTrace: \n" + exceptionParameter.StackTrace); Console.WriteLine("\nexceptionParameter.InnerException: \n" + exceptionParameter.InnerException); } } // calls Method2 static void Method1() { Method2(); } // calls Method3 static void Method2() { Method3(); } // throws an Exception containing an InnerException static void Method3() { // attempt to convert string to int try { int.Parse("Not an integer"); } catch (FormatException formatExceptionParameter) { // wrap FormatException in new Exception throw new Exception("Exception occurred in Method3", formatExceptionParameter); } } }