try { // some code that can potentially throw an exception } catch(Exception ex) { Console.WriteLine("An error occurred: " + ex.Message); Log.Error("Exception caught", ex); }
try { // some code that can potentially throw an exception } catch(Exception ex) { var innerException = ex.InnerException as SomeException; if(innerException != null) { Console.WriteLine("The inner exception message is: " + innerException.Message); } }In this example, we use the "as" keyword to create a reference to the inner exception object and then check if it is of a specific type so that we can access additional details about the exception. Package library: This feature is part of the C# language and does not require any external package or library.