Strategies/techniques for crash reporting in Java
crash, error-handling, java
Solution
I see three cases:
Catastrophes. The JVM itself is either dead or dying. You cannot assume that any of your code will be able to work - for example you can't allocate any memory. Hence in this case you can't reasonably hope to be able to send any diagnostics. The best you can hope for is to have some diagnostics such as core dumps left in the ashes of the dead program. In this case you could on startup of a new run look for such debris and suggest that the user gather it or, rather more effort attempt to assemble a diagnostic package yourself.
The low-level application code does not catch an exception, perhaps a RunTime exception such as a NullPointer exception. In this case you could in your main (assuming you have one) you could catch Exception and have some hope your that your Crash Reporter code will work. Pass the exception, and it's stack trace, to the Crash Reporter.
You low level code catches something really unhealthy. Not enough to terminate process, but worth reporting. Here you not only have the exception to hand but other contextual information. We have rather more to send to the Crash Reporter.
Problem
I'm developing a new Java desktop application and would like to include a crash reporting facility - you know the kind of thing - program crashes, box pops up asking user to click okay to send it, etc. I'm comfortable with how the error will be sent back to our servers - probably via a simple web service. What I'm more unsure about is how the mechanism for capturing the failure should be implemented?. I would welcome any advice from anyone that has implemented something similar.