serhii.net

In the middle of the desert you can say anything you want

14 Feb 2022

python run pdb on exception

Was looking for something similar for months, found it in an unexpected place: Implement –pdb in a python cli

Example from there:

if "--pdb" in sys.argv:
	try:
		bombs()
	except:
		extype, value, tb = sys.exc_info()
		traceback.print_exc()
		pdb.post_mortem(tb)
else:
	bombs()

I changed the flow to this, so I don’t need to call bombs() in two places:

try:
	bombs()
except Exception as e:
	if args.pdb:
		extype, value, tb = sys.exc_info()
		traceback.print_exc()
		pdb.post_mortem(tb)
	else:
		raise e
Nel mezzo del deserto posso dire tutto quello che voglio.