Detailed explanation of Android capture runtime exceptions

Detailed explanation of Android capture runtime exceptions

Android exceptions fall into two categories: checkedexception and uncheckedexception

Checkexception: try () catch is required when compiling code.

Uncheckexception: all runtime exceptions, runtimeException class and its subclasses, occur during app operation. That is, when the app crashes during operation, this exception becomes a runtime exception (such as null pointer). When the app crashes, the user experience is very bad, so we should capture this exception for processing (pop up an interface), and then a better solution is to get this exception and send it back to the server, In this way, when we develop the app, we will know where the code is wrong

After talking for a long time, how to catch it?

Android provides an interface: uncaughtexceptionhandler, which is the internal interface of thread class and has corresponding methods:

The usual solution is to call Thread.setDefaultUncaughtExceptionHandler () in the Application of the project. Note that this method requires an object that implements the UnCaughtExceptionHandler interface. We can customize a class to implement the interface, and then we can get the APP breakdown in onUncaughtException () method.

Thank you for reading, hope to help you, thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>