Created
          April 5, 2016 13:52 
        
      - 
      
- 
        Save svetlyak40wt/c8ed5134a4073d4f2780f018d2089de5 to your computer and use it in GitHub Desktop. 
    This is a demo of broken traceback when reraising exception in python 2.x.
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | """ | |
| This is a demo of broken traceback | |
| when reraising exception in python 2.x. | |
| In this code, "raise e" makes python | |
| lost original traceback, attached to the | |
| exception. It outputs: | |
| Traceback (most recent call last): | |
| File "/tmp/test.py", line 19, in <module> | |
| another() | |
| File "/tmp/test.py", line 14, in another | |
| raise e | |
| RuntimeError: blah | |
| But if you'll fix this code and leave only | |
| "raise" alone, then it will show original | |
| traceback: | |
| Traceback (most recent call last): | |
| File "/tmp/test.py", line 19, in <module> | |
| another() | |
| File "/tmp/test.py", line 12, in another | |
| some() | |
| File "/tmp/test.py", line 8, in some | |
| return bar() | |
| File "/tmp/test.py", line 5, in bar | |
| return foo() | |
| File "/tmp/test.py", line 2, in foo | |
| raise RuntimeError("blah") | |
| RuntimeError: blah | |
| """ | |
| def foo(): | |
| raise RuntimeError("blah") | |
| def bar(): | |
| return foo() | |
| def some(): | |
| return bar() | |
| def another(): | |
| try: | |
| some() | |
| except Exception as e: | |
| raise e | |
| if __name__ == '__main__': | |
| another() | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Давно Бикинг писал статью о вариантах обхода такой ситуации. Одной из идей была, что, ежели
eникак не дополняется, то голыйraiseдолжен справиться с задачей.