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.
394
|
Chapter 7: Exception Handling
is called from a catch block. It takes a single exception object as a parameter and
proceeds to display its information, including information on all inner exceptions
and the exception data block.
Discussion
A typical exception object of type Exception displays the following information if its
ToString method is called:
System.Exception: Exception of type System.Exception was thrown.
at Chapter_Code.Chapter7.TestSpecializedException( ) in c:\book cs cookbook\code\
test.cs:line 286
Example 7-3. Displaying exception information, including information on all inner exceptions and
the exception data block
public static int exceptionLevel = 0;
public static void DisplayException(Exception e)
{
// Increment exception level.
exceptionLevel++;
// Make spacer for level.
string indent = new string('\t',exceptionLevel-1);
// Write out exception level data.
Console.WriteLine(indent + "*** Exception Level {0} " +
"***************************************", exceptionLevel);
Console.WriteLine(indent + "ExceptionType: " + e.GetType( ).Name.ToString( ));
Console.WriteLine(indent + "HelpLine: " + e.HelpLink);
Console.WriteLine(indent + "Message: " + e.Message);
Console.WriteLine(indent + "Source: " + e.Source);
Console.WriteLine(indent + "StackTrace: " + e.StackTrace); ...
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

Joe Mayo
C# Cookbook

C# Cookbook

Stephen Teilhet, Jay Hilyard
Head First C#, 4th Edition

Head First C#, 4th Edition

Andrew Stellman, Jennifer Greene

Publisher Resources

ISBN: 0596100639Supplemental ContentCatalog PageErrata