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)
Using printStackTrace() method − It print the name of the exception, description and complete stack trace including the line where exception occurred. Using toString() method − It prints the name and description of the exception. Using getMessage() method − Mostly used. It prints the description of the exception.
Catching Exceptions in Python In Python, exceptions can be handled using a try statement. The critical operation which can raise an exception is placed inside the try clause. The code that handles the exceptions is written in the except clause.
The sys. exc_clear() statement can be utilized to clear the last thrown exception of the Python interpreter. The following code uses the sys. exc_clear() statement in the except block to ignore an exception and proceed with the code in Python.
ex.GetType().Name
or ex.GetType().FullName
for the fully qualified name.
Try ex.GetType().Name
try { object test = null; test.ToString(); } catch (Exception ex) { Console.WriteLine(ex.GetType().Name); }
Gives this..
NullReferenceException
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With