3 回答

慕標5832272
TA貢獻1966條經驗 獲得超4個贊
else
try
使用ASER子句比向try子句添加額外代碼更好,因為它避免意外捕獲未被try保護的代碼引發的異常.除了陳述。
IOError
try: operation_that_can_throw_ioerror()except IOError: handle_the_exception_somehow()else: # we don't want to catch the IOError if it's raised another_operation_that_can_throw_ioerror()finally: something_we_always_need_to_do()
another_operation_that_can_throw_ioerror()
operation_that_can_throw_ioerror
except
try
finally
else
第二個操作只有在沒有例外的情況下才能運行, 它會在 finally
布洛克 任何 IOError
它不會在這里被抓到

揚帆大魚
TA貢獻1799條經驗 獲得超9個贊
else
try: from EasyDialogs import AskPassword # 20 other lines getpass = AskPasswordexcept ImportError: getpass = default_getpass
try: from EasyDialogs import AskPasswordexcept ImportError: getpass = default_getpasselse: # 20 other lines getpass = AskPassword
except
try: from EasyDialogs import AskPasswordexcept ImportError: getpass = default_getpass return False # or throw Exception('something more descriptive')# 20 other linesgetpass = AskPassword
注:
添加回答
舉報
0/150
提交
取消