エラーコードポータル
PythonPythonエラーコード

BaseExceptionGroup

BaseExceptionGroup

コード BaseExceptionGroup · Pythonが報告した問題です。

これらの例外タイプは両方とも、例外をシーケンス excs でラップします。 msg パラメータは文字列である必要があります。 2 つのクラスの違いは、BaseExceptionGroup は BaseException を拡張し、あらゆる例外をラップできるのに対し、ExceptionGroup は Exception を拡張し、Exception のサブクラスのみをラップできることです。この設計では、Exception は ExceptionGroup をキャッチしますが、BaseExceptionGroup はキャッチしません。 BaseExceptionGroup コンストラクターは、含まれるすべての例外が Exception インスタンスである場合、BaseExceptionGroup ではなく ExceptionGroup を返すため、選択を自動化するために使用できます。一方、ExceptionGroup コンストラクターは、含まれている例外が Exception サブクラスではない場合、TypeError を生成します。 例外グループは、それに含まれる例外のタイプに対して汎用的です。 BaseExceptionGroup は __new__() を定義するため、別のコンストラクター シグネチャが必要なサブクラスは __init__() ではなくそれをオーバーライドする必要があることに注意してください。たとえば、次の例では、exit_code を受け入れ、そこからグループのメッセージを構築する例外グループ サブクラスを定義しています。 ExceptionGroup と同様、Exception のサブクラスでもある BaseExceptionGroup のサブクラスは、Exception のインスタンスのみをラップできます。

Google Translate · 自動翻訳です。専門用語や適用条件は英語の原文で確認してください。

Both of these exception types wrap the exceptions in the sequence excs. The msg parameter must be a string. The difference between the two classes is that BaseExceptionGroup extends BaseException and it can wrap any exception, while ExceptionGroup extends Exception and it can only wrap subclasses of Exception. This design is so that except Exception catches an ExceptionGroup but not BaseExceptionGroup. The BaseExceptionGroup constructor returns an ExceptionGroup rather than a BaseExceptionGroup if all contained exceptions are Exception instances, so it can be used to make the selection automatic. The ExceptionGroup constructor, on the other hand, raises a TypeError if any contained exception is not an Exception subclass. Exception groups are generic over the type of their contained exceptions. Note that BaseExceptionGroup defines __new__(), so subclasses that need a different constructor signature need to override that rather than __init__(). For example, the following defines an exception group subclass which accepts an exit_code and constructs the group’s message from it. Like ExceptionGroup, any subclass of BaseExceptionGroup which is also a subclass of Exception can only wrap instances of Exception.

トラブルシューティング・診断リンク

まず、文書の製品・バージョン・発生環境が現在の状況と一致しているか確認してください。