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.
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.
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.
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 .
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With