I'd like to use to a custom exception to have a user-friendly message come up when an exception of any sort takes place.
What's a good straightforward way of doing this? Are there any extra precautions I should take to avoid interfering with Swing's EDT?
You can use
java.lang.Thread.UncaughtExceptionHandler
which catches all exceptions you haven't cared for yourselfregister it in your app:
and in your GUI you can use
org.jdesktop.swingx.JXErrorPane
from SwingX to show a nice error popup, which informs the user about exceptions.Exception Translation:
It's a good idea to not pollute your application with messages that have no meaning to the end user, but instead create meaningful Exceptions and messages that will translate the exception/error that happened somewhere deep in the implementation of your app.
As per @Romain's comment, you can use Exception(Throwable cause) constructor to keep track of the lower level exception.
From
Effective Java 2nd Edition
, Item 61: