Java Reference
In-Depth Information
} catch (IOException e) {
e.printStackTrace();
}
}
How It Works
The example demonstrates how to use an UncaughtExceptionHandler in con-
junction with SLF4J to log exceptions to a logging file. When logging an exception, it
is good to include the stack trace showing where the exception was thrown. In the ex-
ample, a thread contains an UncaughtExceptionHandler , which utilizes a
lambda expression containing a logger. The logger is used to write any caught excep-
tions to a log file.
Note If an exception is thrown repeatedly, the JVM tends to stop populating the
stack trace in the Exception object. This is done for performance reasons because re-
trieving the same stack trace becomes expensive. If this happens, you will see an excep-
tion with no stack trace being logged. When that happens, check the log's previous
entries and see whether the same exception was thrown. If the same exception has been
thrown previously, the full stack trace will be present on the first logged instance of the
exception.
Search WWH ::




Custom Search