简体   繁体   中英

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM