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(eg NullPointerException
)?
设置一个Thread.UncaughtExceptionHandler打印到指定的文件。
If the main thread crashes, the JVM will print a stacktrace automatically.
For other threads, you can use setUncaughtExceptionHandler .
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.