Print stack trace of the Exception Java Example Program


Syntax

<exception_name>.printStackTrace();

Print stack trace of the Exception Example Program

public class PrintStackTraceOfException {
    public static void main(String[] args) {
        try{
        String text = null;
        String subString = text.substring(3);
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}

Sample Output

java.lang.NullPointerException
	at learnjavaprograms.PrintStackTraceOfException.main(PrintStackTraceOfException.java:16)