2

例外が発生した場合にスロー可能な原因を取得して表示しようとしています:

if (throwable instanof MyException)
    //Do something here..
} else if (throwable instanceof Exception) {
    if (throwable.getCause() != null) {
        //Show the cause here ..
        // throwable.getCause().getLocalizedMessage()
    }
}

式ウォッチャーがnullでない値を持っていることを示している間、私は常に使用時にnull値を取得します。CausegetCause()

ここに画像の説明を入力

原因を突き止めるには?

4

1 に答える 1

3

getCauseとが同じnull場合に戻ります。JDK のスニペットを次に示します。causethis

public synchronized Throwable getCause() {
    return (cause==this ? null : cause);
}

あなたの場合、UsernameNotFoundExceptionあなたが見ている例外はありますか?

于 2013-04-21T22:38:56.280 に答える