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?
Why don't you add a single line like this in your catch block ..which will show you the error message irrespective of How you run your app.
javax.swing.JOptionPane.showMessageDialog(null,"Something is really wrong..Hence notifying you..");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With