how can I get the exception name without getting the stack trace?
I am using exception.toString()
to convert the thrown exception into a string, but I only want the exception name likeNullPointerException
and not the entire stack trace.
How can I solve this?
exception.getClass().getSimpleName();
NOTE: this will not work in case if your exception is an anonymous class (although I have personally never seen an anonymous exception in any production code)