Majid Laissi
Majid Laissi

Reputation: 19788

Display Exception Cause

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.

enter image description here

How to get the cause ?

Upvotes: 2

Views: 162

Answers (1)

Jeff Storey
Jeff Storey

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

Related Questions