Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to automatically break into the debugger when a exception is thrown?

If ones catches an exception outside of the function it is originally thrown, ones loses access to the local stack. As a result one cannot inspect the values of the variables that might have caused the exception.

Is there a way to automatically start break into the debugger (import pdb; pdb.set_trace()) whenever a exception is thrown to inspect the local stack?

like image 887
Framester Avatar asked Sep 23 '13 13:09

Framester


People also ask

How do you break an exception thrown?

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.

How exceptions are used for debugging?

After you have found an exception, or preferably before your software is distributed, you should go through the code and debug it in order to find and repair the erroneous code. There are many different ways to debug and repair code; we will go through some debugging methodologies in this chapter.

What is break in debugger?

If a user-mode debugger is attached, the program will break into the debugger. This means that the program will pause and the debugger will become active.


1 Answers

You don't want to break on every exception; idiomatic Python code uses exceptions heavily (EAFP) so you'd be continually breaking in unrelated code.

Instead, use pdb post-mortem: import pdb; pdb.pm(). This uses sys.last_traceback to inspect the stack including the locals at the throw point.

like image 61
ecatmur Avatar answered Sep 21 '22 06:09

ecatmur