Java Data Type Tutorial - Java Throwable.getCause()








Syntax

Throwable.getCause() has the following syntax.

public Throwable getCause()

Example

In the following code shows how to use Throwable.getCause() method.

//w w w .j  ava 2 s  .c  om
public class Main {
  public static Throwable getDeepestThrowable(Throwable t) {
    Throwable parent = t;
    Throwable child = t.getCause();
    while (null != child) {
      parent = child;
      child = parent.getCause();
    }

    return parent;

  }

}