【发布时间】:2014-09-03 07:58:14
【问题描述】:
默认情况下,我的 Android Studio 似乎不想中断任何异常。在“任何异常”上启用中断开始在实际的 JDE 库中中断。有什么方法可以强制它仅在我的代码中出现异常时中断?
来自 Visual Studio 世界,在此处寻找默认的 VS 调试行为。
【问题讨论】:
标签: debugging exception android-studio breakpoints
默认情况下,我的 Android Studio 似乎不想中断任何异常。在“任何异常”上启用中断开始在实际的 JDE 库中中断。有什么方法可以强制它仅在我的代码中出现异常时中断?
来自 Visual Studio 世界,在此处寻找默认的 VS 调试行为。
【问题讨论】:
标签: debugging exception android-studio breakpoints
中断所有异常,无论捕获还是未捕获:
!(this instanceof java.lang.ClassNotFoundException) com.myapp.*(将其替换为您应用的命名空间前缀)java.*(注意:根据 OP 的问题,不要在 Java 库上中断)android.*(如上,只调试自己的应用代码)【讨论】:
org.junit.*
如果您打开“断点”窗口,它会为您提供很多选项来使其有条件地中断或不中断。您正在寻找的是此处的“类过滤器”——您可以使用例如 Java 包路径指定通配符表达式,它只会在匹配类生成的异常时中断。
【讨论】:
中断代码中的所有异常以及其他未捕获的异常:
此方法过滤掉运行时在正常操作期间抛出的异常类型(不是很异常,是吗?)。它不使用类过滤器,因为它会过滤掉太多;代码中的错误通常会导致运行时类抛出异常(例如,访问末尾的数组列表)。
仅为未捕获异常启用Java Exception BreakPoints / Any exception。
为Exception (java.lang) 类添加一个新的Java Exception BreakPoint,用于捕获和未捕获 异常。启用 Condition 并将其设置为:
!(this instanceof java.lang.ClassNotFoundException || this instanceof android.system.ErrnoException || this instanceof java.io.FileNotFoundException || this instanceof javax.net.ssl.SSLHandshakeException || this instanceof javax.net.ssl.SSLPeerUnverifiedException || this instanceof android.system.GaiException || this instanceof java.net.SocketTimeoutException || this instanceof java.net.SocketException || this instanceof java.security.NoSuchAlgorithmException)
将您遇到的任何其他非异常异常添加到条件中的排除列表中。 (顺便说一句,使用java.lang.Exception 是一种有效地获得第二个“任何异常”条目的方法。)
【讨论】: