Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pretty printing exceptions in C#

Tags:

Is there any API that allows to prints all the exception-related info (stack trace, inner etc...)? Just like when the exception is thrown - all the data is printed to the standard output - is there any dedicated method that does it all?

thanks

like image 606
BreakPhreak Avatar asked Dec 15 '10 13:12

BreakPhreak


People also ask

What is exception StackTrace?

A trace of the method calls is called a stack trace. The stack trace listing provides a way to follow the call stack to the line number in the method where the exception occurs. The StackTrace property returns the frames of the call stack that originate at the location where the exception was thrown.

What is print exception?

Class PrintException encapsulates a printing-related error condition that occurred while using a Print Service instance. This base class furnishes only a string description of the error. Subclasses furnish more detailed information if applicable.

How do I print an exception class?

The Throwable class provides the following three methods to print the exception message: Using printStackTrace Method. Using getMessage() Method. Using toString() Method.

How do I print an increase exception?

To catch and print an exception that occurred in a code snippet, wrap it in an indented try block, followed by the command "except Exception as e" that catches the exception and saves its error message in string variable e . You can now print the error message with "print(e)" or use it for further processing.


2 Answers

Console.WriteLine(exception.ToString()); 
like image 111
jgauffin Avatar answered Oct 19 '22 03:10

jgauffin


the ToString method of Exception does exactly that.

like image 33
Klaus Byskov Pedersen Avatar answered Oct 19 '22 04:10

Klaus Byskov Pedersen