Blinxen
Blinxen

Reputation: 864

Exceptions in Python(multiple try blocks)

I am new to python and I have been wondering if you can do something like this in python.

try:
   something():
if it throws an exception then try this:
   something1():
if it throws an exception again:
   print(exception)

Upvotes: 1

Views: 77

Answers (1)

hspandher
hspandher

Reputation: 16743

Of course you can.

try:
    something()
except Exception as exp:
    try:
        something1()
    except Exception as exp2:
        print(exp, exp2)
        raise exp # in case you want to raise the original exception

Upvotes: 1

Related Questions