Throwable class getCause () método : Aquí, vamos a aprender sobre el método getCause () de la clase Throwable Class con su sintaxis y su ejemplo.
Throwable Class getCause () método
- getCause () Método está disponible en java.lang Class.
- getCause () Método se utiliza para package la causa de esta excepción throwable y vuelve for cuando la causa es si no existen o no se conoce.
- getCause () Método es un método no static, se puede acceder con sólo el objeto class y si tratamos de acceder al método con el nombre class entonces obtendrá un error.
- getCause () Método no throw una excepción en el momento de devolver la causa de este objeto.
Sintaxis:
public Throwable fillInStackTrace();
Parámetro (s):
- No acepta cualquier parámetro.
for valor:
El tipo Return del método es Throwable , devuelve la causa de esta excepción cuando la causa es inexistente o conocido de lo contrario devuelve return cuando la causa es inexistente o no conocida.
Ejemplo:
// Java program to demonstrate the example
// of Throwable fillInStackTrace() method of Throwable
public class FillInStackTrace {
public static void main(String args[]) throws Throwable {
// Creating an object of the class
FillInStackTrace st_tr = new FillInStackTrace();
try {
// It will throw an exception while performing
// divide operation
st_tr.divM();
} catch (Exception ex) {
// By using fillInStackTrace() method is to
// print exception information in detail
ex.fillInStackTrace();
ex.printStackTrace();
}
}
//method calls
public void divM() throws Throwable {
div();
}
// This method will throw an exception
//when number is divide by 0
void div() {
try {
System.out.println(100 / 0);
} catch (ArithmeticException ex) {
throw ex;
}
}
}
salida
java.lang.ArithmeticException: / by zero
at FillInStackTrace.main(FillInStackTrace.java:16)