getCause
の関数を呼び出しているときに null を取得していますThrowable
。
package com.salman.demo;
public class MyClass {
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
NormalClass.testIt();
} catch (Throwable th) {
System.out.println(th.getCause());
}
}
}
package com.salman.demo;
import com.salman.exceptions.ValidationException;
public class NormalClass {
public static void testIt() throws ValidationException {
System.out.println("Inside testIt funtion.");
throw new ValidationException("Validation Exception..");
}
}
実行するMyClass
と、次の出力が出力されます
Inside testIt funtion.
null
ただし、これをデバッグすると、プライベート変数が予期される値に設定されていることがわかりますがValidationException
、そのプライベートフィールドのゲッターを呼び出すとnullが返されます。