Java Throwable getCause() methodIt is used to fetch the cause of the Throwable or null if cause can't be determined. This function fetches the cause that was supplied by one of the constructors or that was set after creation with the initCause(Throwable) method. All the PrintStackTrace methods invoke getCause() method to determine the cause of the Throwable. SyntaxReturnIt returns the cause of the Throwable or null if cause can't be determined. Example 1Test it NowOutput: Cause : java.lang.ArithmeticException: / by zero Example 2Test it NowOutput: java.lang.ArithmeticException: / by zero at ExceptionTest.main(ExceptionTest.java:5) Cause : null
Next TopicJava Throwable
|