Reputation: 8738
Is this the best method for getting the name of a specific Exception in C#:
ex.GetType().ToString()
It is in a generic exception handler:
catch (Exception ex)
Upvotes: 30
Views: 19043
Reputation: 9606
Try ex.GetType().Name
try
{
object test = null;
test.ToString();
}
catch (Exception ex)
{
Console.WriteLine(ex.GetType().Name);
}
Gives this..
NullReferenceException
Upvotes: 16
Reputation: 12899
ex.GetType().Name
or ex.GetType().FullName
for the fully qualified name.
Upvotes: 48