adsense


Thursday, 29 October 2015

JAVA EXAMPLES EXCEPTION METHOD PAGE 125

COMPUTER LANGUAGES HTML,C,C++.JAVA,.NET AND MULTIMEDIA basics and programs click home button



JAVA EXAMPLES EXCEPTION METHOD






Java Examples - Exception Methods


Problem Description:
How to handle the exception methods ?
Solution:
This example shows how to handle the exception methods by using System.err.println() method of System class .
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();
       }
 }
Result:
The above code sample will produce the following result.
Caught Exception
getMassage(): My Exception
gatLocalisedMessage(): My Exception
toString():java.lang.Exception: My Exception
print StackTrace():
 java.lang.Exception: My Exception
   at ExceptionMethods.main(ExceptionMeyhods.java:12)


No comments: