try_reraise2.py 746 B

1234567891011121314151617181920212223242526272829303132
  1. # Reraise not the latest occurred exception
  2. def f():
  3. try:
  4. raise ValueError("val", 3)
  5. except:
  6. try:
  7. print(1)
  8. raise TypeError
  9. except:
  10. print(2)
  11. try:
  12. print(3)
  13. try:
  14. print(4)
  15. raise AttributeError
  16. except:
  17. print(5)
  18. pass
  19. print(6)
  20. raise
  21. except TypeError:
  22. print(7)
  23. pass
  24. print(8)
  25. print(9)
  26. # This should raise original ValueError, not the most recently occurred AttributeError
  27. raise
  28. try:
  29. f()
  30. except ValueError as e:
  31. print(repr(e))