I believe that exceptions thrown by the GUI thread, which cannot go to a console, are outright discarded. They don't go anywhere.
Also, unchecked exceptions are definitely not necessarily "to use in case of violation of the contract of a method". There's a lot of controversy on this subject - when to use checked and unchecked exceptions and why, why you would or would not want to catch exceptions, etc. This is even more complicated when considering calls to other libraries, calls into the Java libraries, etc. You may also want to do something with even an unchecked exception. (For example, the parsing methods in Java's Number classes throw unchecked exceptions that you almost certainly want to catch.)
I would always catch even unchecked exceptions from the GUI thread somewhere, because it's much more user-friendly to display a useful dialog box than to have an exception show up on the console. Exceptions are for developers, not users. In Java there is a special mechanism for doing this that will allow you to catch all GUI exceptions and do something constructive with them before they hit the console. You can call Thread.setDefaultUncheckedExceptionHandler()
to set the default method for handling unchecked exceptions in all threads, and also call System.setProperty("sun.awt.exception.handler", "string-that-names-exception-handler-class")
so that the system will pass exceptions to the class of your choice. As far as I can remember, the class for both of those needs to implement Thread.UncaughtExceptionHandler
.
EDIT: Credit to AKF and others, they do go to stderr. The problem is that typical methods of launching GUI apps don't involve redirecting stderr to a file; stderr and stdout are just discarded. What I would strongly recommend is using a logging facility of some sort and then logging, not only the exceptions, but other interesting things that happen in your code. For example, I set up a primitive logging facility for some research code of mine so that it would log when it starts certain algorithm code, how long it takes, which experimental case it's on, etc. However for production code I'd probably want to take the time to learn and use a real logging facility such as log4j, java.util.logging
, or whatever else people are using these days.