Skip to main content
Reduced wordiness
Source Link

If you don't want the second do_smth2() to run if first do_smth1() worked, then just add the second try under the first except. If do_smth1() worked, then do_smth2() will not be tried.

try:
    x=do_smth1()
except:
    try:
        x=do_smth2()
    except:
        x="Both Failed"

print ("Both Failed"x)

If you don't want the second do_smth2() to run if first do_smth1() worked, then just add the second try under the first except. If do_smth1() worked, then do_smth2() will not be tried.

try:
    x=do_smth1()
except:
    try:
        x=do_smth2()
    except:
        print ("Both Failed")

If do_smth1() worked, then do_smth2() will not be tried.

try:
    x=do_smth1()
except:
    try:
        x=do_smth2()
    except:
        x="Both Failed"

print (x)
Source Link

If you don't want the second do_smth2() to run if first do_smth1() worked, then just add the second try under the first except. If do_smth1() worked, then do_smth2() will not be tried.

try:
    x=do_smth1()
except:
    try:
        x=do_smth2()
    except:
        print ("Both Failed")