debugging - On Error Goto in Python -
i've seen several answers on topic - of (using python 3.6) out of date - , i'm still no clearer on best way this.
i wish able run script, , if encounters error, jumps point pauses , can test value of local variables see might amiss.
in other languages (eg vba) have on error goto errorhandler, put break point in error handler, print out error description , line number came, use locals or immediate window see values variable have @ point.
i don't want whole bunch of try/except statements, nor wish run in debug mode every time.
is there simple pythonesque way pause while have @ problem?
you'll find pdb module useful.
the module
pdbdefines interactive source code debugger python programs. supports setting (conditional) breakpoints , single stepping @ source line level, inspection of stack frames, source code listing, , evaluation of arbitrary python code in context of stack frame. supports post-mortem debugging , can called under program control.
pdb useful setting breakpoints , post-mortem debugging. believe you're looking for.
again, docs:
the typical usage break debugger running program insert
import pdb; pdb.set_trace()at location want break debugger. can step through code following statement, , continue running without debugger using
continuecommand.
Comments
Post a Comment