Reputation: 249
My client is testing my beta phase Java application on a data that he cannot provide me with (privacy reasons). Although I implemented the handling of most exceptions, application crashes on rare occasions.
Can I log the stacktrace of an uncaught exception to a file so that tester can provide me with it(e.g. NullPointerException
)?
Upvotes: 0
Views: 112
Reputation: 24271
This is exactly the thing what UncaughtExceptionHandler
concept is about.
Basically you are able to register a piece of code to be executed when the exception reaches the top of the stack.
Upvotes: 0
Reputation: 262684
If the main thread crashes, the JVM will print a stacktrace automatically.
For other threads, you can use setUncaughtExceptionHandler.
Upvotes: 0
Reputation: 68616
Set a Thread.UncaughtExceptionHandler that prints to the specified file.
Upvotes: 3