Javatpoint Logo
Javatpoint Logo

Java Throwable getCause() method

It 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.

Syntax

Return

It returns the cause of the Throwable or null if cause can't be determined.

Example 1

Test it Now

Output:

Cause : java.lang.ArithmeticException: / by zero

Example 2

Test it Now

Output:

java.lang.ArithmeticException: / by zero
	at ExceptionTest.main(ExceptionTest.java:5)
Cause : null
Next TopicJava Throwable



Help Others, Please Share

facebook twitter pinterest