Get the name of a specific exception

Is this the best method to get the name of a specific exception in C #:

ex.GetType().ToString() 

In the general exception handler:

 catch (Exception ex) 
+6
source share
2 answers

ex.GetType().Name or ex.GetType().FullName for the full name.

+10
source

Try ex.GetType().Name

 try { object test = null; test.ToString(); } catch (Exception ex) { Console.WriteLine(ex.GetType().Name); } 

Gives it.

 NullReferenceException 
+3
source

Source: https://habr.com/ru/post/1013447/


All Articles