Reputation: 19788
I'm trying to get the cause of a throwable to display it in case of an exception:
if (throwable instanof MyException)
//Do something here..
} else if (throwable instanceof Exception) {
if (throwable.getCause() != null) {
//Show the cause here ..
// throwable.getCause().getLocalizedMessage()
}
}
I always get a null
value for the Cause
when using getCause()
while the Expression watcher show that it has a not null value.
How to get the cause ?
Upvotes: 2
Views: 162
Reputation: 57202
getCause
returns null
if the cause
and this
are the same. Here is a snippet from the JDK:
public synchronized Throwable getCause() {
return (cause==this ? null : cause);
}
In your case, is the UsernameNotFoundException
the exception you're looking at?
Upvotes: 3