Java Throwable printStackTrace() method – Javatpoint

Java Throwable printStackTrace() method

The printStackTrace() method of Java Throwble class is used to print the Throwable along with other details like classname and line number where the exception occurred.

Syntax

Return

Example 1

Output:

java.lang.ArithmeticException: / by zero
	at ThrowablePrintStackTrace.main(ThrowablePrintStackTrace.java:5)
Cause : null

Example 2

Output:

Inside exceptionTest() method
java.lang.Exception: Throwing localized message!
	at ThrowablePrintStackTraceExample2.exceptionTest(ThrowablePrintStackTraceExample2.java:11)
	at ThrowablePrintStackTraceExample2.main(ThrowablePrintStackTraceExample2.java:4)

Next Topic

Java Throwable