android studio break,Android Studio IDE: Break on Exception

可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):

问题:

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?

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

回答1:

To break on all exceptions, caught or uncaught:

Open the Breakpoints window via Run -> View Breakpoints.

The Breakpoints dialog appears. In the left pane, scroll to the bottom. Select Any exception under Java Exception Breakpoints

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

6c1555302777729326ca3efa0910d9ec.png

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

6c1555302777729326ca3efa0910d9ec.png (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)

6c1555302777729326ca3efa0910d9ec.png

Press OK, then dismiss the Breakpoints dialog.

回答2:

If you open up the Breakpoints window, it gives you quite a few options to have it conditionally break or not. What you're looking for is the "Class filters" here -- you can specify a wildcard expression with, for example, a Java package path, and it will only break for exceptions generated from matching classes.

回答3:

To break on all exceptions in your code and other exceptions if uncaught:

This methods filters out the exception types that the runtime throws during normal operation (not very exceptional, are they?). It doesn't use the class filter, since it would filter out too much; bugs in your code often cause runtime classes to throw exceptions (e.g. accessing an array list past the end).

Enable Java Exception BreakPoints / Any exception for uncaught exceptions only.

Add a new Java Exception BreakPoint for the Exception (java.lang) class for caught and uncaught exceptions. Enable Condition and set it to this:

!(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)

Add to the exclusion list in the condition any other non-exceptional exceptions you encounter. (BTW, using java.lang.Exception is a way of effectively getting a second "Any exception" entry.)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值