-2
Pythonのtry
、except
ブロックでは、except:
を指定子なしで使用することができるのであれば、なぜelse
が必要なのですか?指定子なしのexpectとelseの違いは?
Pythonのtry
、except
ブロックでは、except:
を指定子なしで使用することができるのであれば、なぜelse
が必要なのですか?指定子なしのexpectとelseの違いは?
try
、except
、else
、およびfinally
はオフの状態です。ここで
はhttps://docs.python.org/2/tutorial/errors.htmlを見てから、一緒にどのようにすべての作業の要約です:
try:
#Try something that might raise an exception
except <exception specifier>:
#Code here will only run if the exception that came up was the one specified
except:
#Except clause without specifier will catch all exceptions
else:
#Executed if try clause doesn't raise exception
#You can only have this else here if you also have except blocks
finally:
#Runs no matter what
は、あなたが二番目のを試してみましたか? – khelwood
このリンクをクリックしてください。うまく説明しました。 http://stackoverflow.com/questions/16138232/is-it-a-good-practice-to-use-try-except-else-in-python –