Is there a way to print an exception message in Java without the exception?
When I try the following piece of code:
try {
// statements
} catch (javax.script.ScriptException ex) {
System.out.println(ex.getMessage());
}
The output is:
Invalid JavaScript code: sun.org.mozilla.javascript.internal.EvaluatorException:
missing } after property list (<Unknown source>) in <Unknown source>;
at line number 1
Is there a way to print the message without the exception information, source and line number information. In other words, the message I would like to print in the output is:
missing } after property list
getCause()to get the inner-most exception andgetMessage()on that, but I wouldn't guarantee that the line number won't be there. It's a rather unusual usecase, can you tell what you want to do? If you just want to output a user-friendly message for a front-end, you're just gonna have to customize it, if it's meant for devs anyway -- the whole thing is much friendlier.