calls GetBaseException and outputs the error message of the initial exception. : Exception Class : Language Basics C# Source Code


Custom Search

C# Source Code » Language Basics » Exception Class »

 

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");
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» Exception Class