cknd / stackprinter

Debugging-friendly exceptions for Python
MIT License
1.28k stars 37 forks source link

Add option to show the parent frames of the exception handling site #27

Closed cknd closed 3 years ago

cknd commented 4 years ago

Following the suggestion by https://github.com/cknd/stackprinter/issues/26 , this adds an option to show caller frames of the frame where an exception is handled (& printerd). By default, Python tracebacks only show the frames below the exception handling site (i.e. you only only see what happened inside your try block, but you don't see which prior calls have led to that block). This option adds such parent frames to the printout.

It seems to be helpful in this case and things like this Qt example

alexmojaki commented 4 years ago

Beware that tracebacks freeze the line number where the exception happened, while frames do not. If you format the stack some time after the frames had moved on it'll show the wrong thing. Although I can't think how this would happen unless you stored the traceback object.

cknd commented 4 years ago

Yes, and that already happens in the frame of the handler, which moves on to.. well, the handler (I think I don't print that now). If tb objects are stored, all bets are off as well, of course.

This is pretty much the reason why I print a separation message between the 'true' traceback frames and the outer ones, and why it's off by default. It's pretty much a niche/specialist feature