Print Stack Trace In Java
Chapter:
Exception Handling
Last Updated:
03-08-2016 18:57:50 UTC
Program:
/* ............... START ............... */
public class JavaPrintStackTrace {
public static void main(String[] args) {
try {
int i = 100/0;
} catch (Exception e) {
e.printStackTrace();
}
}
}
/* ............... END ............... */
Output
java.lang.ArithmeticException: / by zero
at ExceptionHandling.JavaPrintStackTrace.main(JavaPrintStackTrace.java:6)
Notes:
-
The java.lang.Throwable.printStackTrace() method prints this throwable and its backtrace to the standard error stream. It prints a stack trace for this Throwable object on the error output stream that is the value of the field System.err.
- Exception handling program that prints a stack trace.
- Syntax : public void printStackTrace().
Tags
Stack Trace, Exception, Java