Reputation: 11458
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
Upvotes: 32
Views: 47705
Reputation: 641
For printing exceptions in C#, you can use Debug.WriteLine():
try
{
reader = cmd.ExecuteReader();
}
catch (Exception ex)
{
Debug.WriteLine("<<< catch : "+ ex.ToString());
}
Also, you can use this for other exceptions, for example with MySqlException:
try
{
reader = cmd.ExecuteReader();
}
catch (MySqlException ex)
{
Debug.WriteLine("<<< catch : "+ ex.ToString());
}
But, if you need printing a Exception's Message, you have to use Message:
try
{
reader = cmd.ExecuteReader();
}
catch (MySqlException ex)
{
Debug.WriteLine("<<< catch : "+ ex.Message);
}
Upvotes: 1
Reputation: 121067
the ToString
method of Exception
does exactly that.
Upvotes: 7