2

In Python, can an exception be caught from an exception, and from the original try, with the same except statement?

For example, in the following code:

try:
    risky_operation() # This could raise a or b, or it could work
except a:
    simple_operation() # This could raise b, or it could work
except b:
    guaranteed_operation() # This will always work

Would guaranteed_operation() be called if risky_operation() raised b? Or would I have to do:

try:
    risky_operation() # This could raise a or b, or it could work
except a:
    try:
        simple_operation() # This could raise b, or it could work
    except b:
        guaranteed_operation() # This will always work
except b:
    guaranteed_operation() # This will always work
Foxocube
  • 710
  • 9
  • 32

0 Answers0