Java Exception Methods Example
Chapter:
Exception Handling
Last Updated:
04-09-2016 16:04:05 UTC
Program:
/* ............... START ............... */
public class JavaExceptionMethod {
public static void main(String[] args) {
try {
throw new Exception("My Exception");
} catch (Exception e) {
System.err.println("Caught Exception");
System.err.println("getMessage():" + e.getMessage());
System.err.println("getLocalizedMessage():"
+ e.getLocalizedMessage());
System.err.println("toString():" + e);
System.err.println("printStackTrace():");
e.printStackTrace();
}
}
}
/* ............... END ............... */
Output
Caught Exception
getMessage():My Exception
getLocalizedMessage():My Exception
toString():java.lang.Exception: My Exception
printStackTrace():
java.lang.Exception: My Exception
at ExceptionHandling.JavaExceptionMethod.main(JavaExceptionMethod.java:7)
Tags
Exception Methods, Java, Exception