Android Studio IDE:发生异常时中断 [英] Android Studio IDE: Break on Exception

查看:51
本文介绍了Android Studio IDE:发生异常时中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,我的 Android Studio 似乎不想中断任何异常.在任何异常"上启用中断会在实际 JDE 库中开始中断.有什么方法可以强制它仅在我的代码中出现异常时中断?

It seems my Android Studio does not want to break on any exception by default. Enabling break on "Any Exception" starts breaking within actual JDE libraries. Is there any way to force it to break only on exceptions within my code only?

来自 Visual Studio Universe,在这里寻找默认的 VS 调试行为.

Coming from Visual Studio universe, looking for the default VS debug behavior here.

推荐答案

打破所有异常,捕获或未捕获:

  1. 通过运行 -> 查看断点打开断点窗口.
  2. 出现断点对话框.在左侧窗格中,滚动到底部.在Java Exception Breakpoints
  3. 下选择任何异常
  4. 选择任何例外后,在右侧窗格中进行如下配置:
    • 暂停:选中
    • 全部:选中
    • 条件:!(this instanceof java.lang.ClassNotFoundException)
    • 通知:捕获的异常未捕获的异常都被选中
  1. Open the Breakpoints window via Run -> View Breakpoints.
  2. The Breakpoints dialog appears. In the left pane, scroll to the bottom. Select Any exception under Java Exception Breakpoints
  3. With Any exception selected, on the right pane, configure as follows:
    • Suspend: checked
    • All: selected
    • Condition: !(this instanceof java.lang.ClassNotFoundException)
    • Notifications: both Caught exception and Uncaught exception selected

  1. 定义用于指定调试器应该中断的库的命名空间的过滤器:选中类过滤器复选框以启用类过滤(正如@Scott Barta 提到的).然后单击...(省略号)按钮打开类过滤器对话框.通过单击 (添加模式)按钮指定类命名空间模式.进入:
    • com.myapp.*(将其替换为您应用的命名空间前缀)
    • java.*(注意:根据 OP 的问题,忽略这一点以免破坏 Java 库)
    • android.*(如上,只调试自己的应用代码)
    • 根据需要添加任何其他命名空间(例如 3rd 方库)
  1. Define filters that specify namespaces of libraries that the debugger should break on: Check the Class filters checkbox to enable class filtering (as mentioned by @Scott Barta). Then click the ... (elipsis) button to open the Class Filters dialog. Specify class namespace patterns by clicking on the (Add Pattern) button. Enter:
    • com.myapp.* (replace this with the namespace prefix of your app)
    • java.* (note: as per OP's question, leave this out to NOT break on Java libraries)
    • android.* (as above, leave out to just debug own app code)
    • Add any additional namespaces as necessary (e.g. 3rd party libraries)

  1. 确定,然后关闭断点"对话框.
  1. Press OK, then dismiss the Breakpoints dialog.

这篇关于Android Studio IDE:发生异常时中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆