Throwable getCause() method in Java with Examples Last Updated : 12 Apr, 2023 Comments Improve Suggest changes Like Article Like Report The getCause() method of Throwable class is the inbuilt method used to return the cause of this throwable or null if cause can't be determined for the Exception occurred. This method help to get 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 of Throwable class invoke getCause() method to determine the cause of the Throwable or Exception. In simple terms, it can be said that this method returns the cause because of which Exception occurred. Syntax: public Throwable getCause() Return Value: This method returns the cause of this Throwable or null if cause can't be determined. Below programs demonstrate the getCause() method of Throwable Class: Example 1: Java // Java program to demonstrate // the getCause() Method. import java.io.*; class GFG { // Main Method public static void main(String[] args) throws Exception { try { // divide the numbers divide(2, 0); } catch (ArithmeticException e) { System.out.println("Cause of Exception: " + e.getCause()); } } // method which divides two number public static void divide(int a, int b) throws Exception { try { // divide two numbers int i = a / b; } catch (ArithmeticException e) { // initializing new Exception with cause ArithmeticException exe = new ArithmeticException(); exe.initCause(e); throw(exe); } } } Output:Cause of Exception: java.lang.ArithmeticException: / by zero Example 2: Java // Java program to demonstrate // the getCause() Method. import java.io.*; class GFG { // Main Method public static void main(String[] args) throws Exception { try { // divide the numbers divide(2, 0); } catch (ArithmeticException e) { System.out.println("Cause of Exception : " + e.getCause()); } } // method which divides two number public static void divide(int a, int b) throws Exception { // divide two numbers int i = a / b; } } Output:Cause of Exception : null References: https://docs.oracle.com/javase/10/docs/api/java/lang/Throwable.html#getCause() Comment More infoAdvertise with us Next Article Throwable getCause() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Exceptions Java-lang package Java-Exception Handling Java-Functions java-Throwable +2 More Practice Tags : Java Similar Reads Throwable getMessage() method in Java with Examples The getMessage() method of Throwable class is used to return a detailed message of the Throwable object which can also be null. One can use this method to get the detail message of exception as a string value. Syntax: public String getMessage() Return Value: This method returns the detailed message 2 min read Throwable getSuppressed() method in Java with Examples The getSuppressed() method of Throwable class used to return an array containing all of the exceptions that were suppressed to deliver this exception typically this suppression done by the try-with-resources statement. In order to deliver Exception If no exceptions were suppressed or suppression is 2 min read Throwable getStackTrace() method in Java with Examples The getStackTrace() method of Throwable class used to return an array of stack trace elements which is the stack trace information printed by printStackTrace(). In the array of stack trace elements(assuming the array's length is non-zero), each element represents one stack frame. The first element o 3 min read Throwable initCause() method in Java with Examples The initCause() method of Throwable class is used to initialize the cause of this Throwable with the specified cause passed as a parameter to initCause(). Actually, the cause is throwable that caused this throwable Object to get thrown when an exception occurs. This method can be called only once. G 3 min read Throwable getLocalizedMessage() method in Java with Examples The getLocalizedMessage() method of Throwable class is used to get a locale-specific description of the Throwable object when an Exception Occurred. It helps us to modify the description of the Throwable object according to the local Specific message. For the subclasses which do not override this me 2 min read Like