第10章 エラー処理
AMQ Python でのエラーは、以下の 2 つの方法で処理できます。
- 例外のキャッチ
- AMQP プロトコルまたは接続エラーを傍受するためのイベント処理関数の上書き
10.1. 例外のキャッチ
AMQ Python が出力するすべての例外は、ProtonException
クラスから継承され、Python Exception
クラスから継承されます。
以下の例は、AMQ Python から発生した例外をキャッチする方法を示しています。
例: API 固有の例外処理
try: # Something that might throw an exception except ProtonException as e: # Handle Proton-specific problems here except Exception as e: # Handle more general problems here }
API 固有の例外処理が必要ない場合は、ProtonException
が継承されるため、ProtonException
のみをキャッチする必要があります。