Methods to Print Exception Information in Java

In Java we can use following methods to print exception information. Throwable class in Java defines all these methods to print exception informatio.

MethodPrint Format
printStackTrace()Name of exception: Description stack trace
toString()Name of exception: Description
getMessage()Description
public class ExceptionHandling {
    public static void main(String[] args) {
        try {
            System.out.println(10 / 0);
        }
        catch (Exception e){
            e.printStackTrace();
            System.out.println(e.toString());
            System.out.println(e.getMessage());
        }
    }
}
Methods to Print Exception Information in Java

Similar Java Tutorials