Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging an exception in an empty catch block

I'm debugging a production application that has a rash of empty catch blocks sigh:

try {*SOME CODE*}
catch{}

Is there a way of seeing what the exception is when the debugger hits the catch in the IDE?

like image 711
Rikalous Avatar asked Sep 02 '08 15:09

Rikalous


People also ask

How do you handle empty catch blocks?

AVOID empty catch blocks. In general, empty catch blocks should be avoided. In cases where they are intended, a comment should be provided to explain why exceptions are being caught and suppressed. Alternatively, the exception identifier can be named with underscores (e.g., _ ) to indicate that we intend to skip it.

What happens if catch block is empty?

It will generate an exception that is caught by the catch block. The catch block catches and handles the exception. If the catch block is empty then we will have no idea what went wrong within our code.

Can exception be resolved in catch block?

The purpose of a try-catch block is to catch and handle an exception generated by working code. Some exceptions can be handled in a catch block and the problem solved without the exception being rethrown; however, more often the only thing that you can do is make sure that the appropriate exception is thrown.

How do I debug an exception?

Tell the debugger to break when an exception is thrownIn the Exception Settings window (Debug > Windows > Exception Settings), expand the node for a category of exceptions, such as Common Language Runtime Exceptions. Then select the check box for a specific exception within that category, such as System.


2 Answers

In VS, if you look in the Locals area of your IDE while inside the catch block, you will have something to the effect of $EXCEPTION which will have all of the information for the exception that was just caught.

like image 186
AdamB Avatar answered Oct 22 '22 01:10

AdamB


In Visual Studio - Debug -> Exceptions -> Check the box by "Common Language Runtime Exceptions" in the Thrown Column

like image 22
Mike Schall Avatar answered Oct 21 '22 23:10

Mike Schall