What is the best way to have a (Java) program recognize it crashed last time it ran and show a message along the lines of "it looks like this program crashed on you last time. Report this problem here: [email protected] ...."
Is there a recommended way of doing this? (Bad?) ideas I had would be:
There are three reasons why a Java program can crash:
try-catch
in main
.main
also. I usually catch Throwable
in main
. See below for a template.Thread.setDefaultUncaughtExceptionHandler()
.new File(...).deleteOnExit()
. Java will clean it up for you if it gets a chance.The problem with deadlocks is how to detect that you have a deadlock. I haven't seen a consistent way to do that, yet.
import org.apache.commons.lang.exception.ExceptionUtils;
public class Demo
{
public static void main (String[] args)
{
try
{
Demo obj = new Demo ();
obj.run (args);
System.out.println ("Done.");
}
catch (Throwable t)
{
ExceptionUtils.printRootCauseStackTrace (t);
}
}
}
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