語法 :: try 陳述句

語法一

try:
    try_suite
except:
    except_suite

語法二

try:
    try_suite
except:
    except_suite
else:
    else_suite

語法三

try:
    try_suite
except:
    except_suite
finally:
    else_suite

語法四

try:
    try_suite
except:
    except_suite
else:
    else_suite
finally:
    finally_suite

當 try_suite 正常完成之後 , else_suite 就會被執行 , 但是如果 try_suite 在執行過程中引發例外 , 則 else_suite 不會被執行 . 但不論如何 , finally_suite 總是會被執行 .

語法五

try:
    try_suite
except exception:
    except_suite

語法六

try:
    try_suite
except (exception1,exception2):
    except_suite

語法七

try:
    try_suite
except (exception1,exception2) as variable:
    except_suite

語法八

try:
    try_suite
except (exception1,exception2) as variable1:
    except_suite1
except (exception3,exception4) as variable2:
    except_suite2

results matching ""

    No results matching ""