调试时强制异常 [英] Force exception while debugging

查看:112
本文介绍了调试时强制异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在调试时强制执行异常

Is it possible to force an exception to be thrown while debugging.

让我给你一个示例:我正在调试一些我从互联网下载页面的代码。当互联网连接丢失或网卡关闭时,应抛出一个IOException,但是执行被阻止(在第二行)

Let me give you an example: I am debugging some code where I download a page from the internet. When the Internet connection is lost, or network card is down, an IOException should be thrown, BUT instead the execution is blocking (on the second line)

URLConnection connection = requestURL.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));

调试时我需要一种强制抛出异常的方法

I need a way to force throwing an exception while debugging when the code is blocking so I can jump to the catch block.

我正在使用netbeans BTW。

I am using netbeans BTW.

当执行线程暂停时手动添加调试

While Debugging = added manually when the execution thread is paused.

编辑:换句话说,我需要注入 - 运行时调用异常,而不影响当前代码!

EDIT: In other words, I need to inject - Invoke an exception while running, without affecting current code !

谢谢。

推荐答案

我会找到正在等待的变量,在eclipse的表达式窗口中,调用该变量的notify,然后我将 null 输出该变量,以便同步的块将抛出一个 NullPointerException

I would find the variable that is being waited on, and in the expression window in eclipse, call notify on that variable, then i would null out that variable, so that the synchronized block would throw a NullPointerException.

这篇关于调试时强制异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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