特定の例外をキャッチし、それに応じて処理したいと考えています。次に、他の例外が必要とする一般的な処理を続行して実行したいと考えています。
C のバックグラウンドを持っていたので、以前は goto を使用して目的の効果を達成できたはずです。
これは私が現在行っていることであり、正常に動作します:
try:
output_var = some_magical_function()
except IntegrityError as zde:
integrity_error_handling()
shared_exception_handling_function(zde) # could be error reporting
except SomeOtherException as soe:
shared_exception_handling_function(soe) # the same function as above
名前:
つまり、次のことを行う「Pythonic」の方法はありますか:
try:
output_var = some_magical_function()
except IntegrityError as zde:
integrity_error_handling()
except ALLExceptions as ae: # all exceptions INCLUDING the IntregityError
shared_exception_handling_function(ae) # could be error reporting
注意: finally 句については承知しています。これは整理 (つまり、ファイルを閉じること) を目的としたものではありません。