Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force exception while debugging

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

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.

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 !

Thank you.

like image 342
FearUs Avatar asked Mar 05 '11 17:03

FearUs


People also ask

How exceptions are used for debugging?

When an exception occurs, the debugger writes an exception message to the Output window. It may break execution in the following cases when: An exception is thrown that isn't handled. The debugger is configured to break execution before any handler is invoked.

How do you force an exception?

Throwing an exception is as simple as using the "throw" statement. You then specify the Exception object you wish to throw. Every Exception includes a message which is a human-readable error description. It can often be related to problems with user input, server, backend, etc.

How do I stop exception breakpoint?

Remove breakpoints For non-exception breakpoints: click the breakpoint in the gutter. For all breakpoints: from the main menu, select Run | View Breakpoints Ctrl+Shift+F8 , select the breakpoint, and click Remove Delete .

How do I allow exceptions in Visual Studio?

You can open the exception settings window by navigating from Debug -> Windows -> Exception Settings. With Visual Studio 2017, it has some additional features and which is quite useful. You can now set the condition on the exception in the Exception settings Windows.


1 Answers

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.

like image 131
MeBigFatGuy Avatar answered Oct 23 '22 07:10

MeBigFatGuy