For the runnable Jar programs I create, I can read the unhandled exceptions if I run it from the command prompt (java -jar myprogram.jar
).
Example code:
public static void main(String args[]) {
try {
EntireProgram();
} catch (Throwable t) {
throw new Error("somehow our error handling code has errors");
}
}
public static void EntireProgram() {
System.out.println(1 / 0);
}
Command line output:
However, if I run the Jar program by double-clicking it (expected of most end-users), the unhandled exceptions stay silent. I've noticed that this is in contrast to "native Windows programs" which I believe have unhandled exceptions handled by the OS default handler (modal dialog message):
The advantage of handling unhandled exceptions this way is that the user will know something wrong has happened (and perhaps report it, hopefully).
How can I make my program's unhandled exceptions be handled in such a way?