How to handle the exception methods?
SolutionThis example shows how to handle the exception methods by using System.err.println() method of System class.
public class NewClass { 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)
java_exceptions.htm
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4