Mega Code Archive

 
Categories / C# / Language Basics
 

Calls GetBaseException and outputs the error message of the initial exception

using System; public class Starter {     public static void Main() {         try {             MethodA();         } catch (Exception except) {             Exception original = except.GetBaseException();             Console.WriteLine(original.Message);         }     }     public static void MethodA() {         try {             MethodB();         } catch (Exception except) {             throw new ApplicationException("Inner Exception", except);         }     }     public static void MethodB() {         throw new ApplicationException("Innermost Exception");     } }