How do I prevent exception catching in Android?

前端 未结 4 637
北荒
北荒 2021-01-22 17:50

I\'m trying to develop an application for Android, but I\'m having difficulties tracing the source and cause of each exception I get in the process. My code runs in an Activity,

4条回答
  •  南笙
    南笙 (楼主)
    2021-01-22 18:39

    Sounds to me like you should be wrapping your code in question in a try/catch block so you can (A) gracefully handle the exception and (B) Be able to set a breakpoint in the catch block and inspect your variables while debugging. Or am I misunderstanding?

    edit:

    As an example, if you have an Activity and you're in your onCreate (my Android-fu is a little rusty) and it's

    public void onCreate(Bundle blahblah) {
      My code here
    }
    

    you would instead do

    public void onCreate(Bundle blahblah) {
      try { 
        My code here
      } catch (Exception e) {
        Log.d(Do something to print your stacktrace here); <-- Set your breakpoint here
      }
    }
    

提交回复
热议问题