Skip to Main Content
C# Cookbook, 2nd Edition
book

C# Cookbook, 2nd Edition

by Jay Hilyard, Stephen Teilhet
January 2006
Intermediate to advanced content levelIntermediate to advanced
1184 pages
43h 23m
English
O'Reilly Media, Inc.
Content preview from C# Cookbook, 2nd Edition
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
382
|
Chapter 7: Exception Handling
{
Console.WriteLine("In outer catch. ReThrown error == " + e.Message);
}
finally
{
Console.WriteLine("In outer finally");
}
}
you will get the following output:
In outer try
In inner try
An Overflow occurred. Error message == Arithmetic operation resulted in an
overflow.
In inner finally
An error occurred in the finally block. Error message == Oops
In outer catch. ReThrown error == Arithmetic operation resulted in an overflow.
In outer finally
By handling exceptions within the inner finally block, you assure that the correct
rethrown exception bubbles up to the outer exception handler.
When writing a finally block, consider placing a separate try-catch
around the code.
See Also
See the “Error Raising and Handling Guidelines” topic and the “throw,” “try,”
“catch,” and “finally” keywords in the MSDN documentation.
7.6 Handling Exceptions Thrown from Methods
Invoked via Reflection
Problem
Using reflection, you invoke a method that generates an exception. You want to
obtain the real exception object and its information in order to diagnose and fix the
problem.
Solution
The real exception and its information can be obtained through the InnerException
property of the TargetInvocationException that is thrown by MethodInfo.Invoke.
Discussion
The following example shows
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# Cookbook

C# Cookbook

Stephen Teilhet, Jay Hilyard
C# Cookbook

C# Cookbook

Joe Mayo
Head First C#, 4th Edition

Head First C#, 4th Edition

Andrew Stellman, Jennifer Greene

Publisher Resources

ISBN: 0596100639Supplemental ContentCatalog PageErrata