How do I log an exception?
Category: java.util.logging, viewed: 1826 time(s).
In this example you can see how we can log an exception when it occures. In
the code below we are trying to parse an invalid date which will give us a
ParseException. To log the exception we call the Logger.log()
method, passes the logger Level, add some user friendly message and
the Throwable object.
The code above will produce the following log message.
27 Apr 09 23:32:17 org.kodejava.example.util.logging.LoggingException main SEVERE: Error parsing date java.text.ParseException: Unparseable date: "12/30/1990" at java.text.DateFormat.parse(DateFormat.java:337) at org.kodejava.example.util.logging.LoggingException.main(LoggingException.java:27) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
