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.
トラブルシューティング・診断リンク
まず、文書の製品・バージョン・発生環境が現在の状況と一致しているか確認してください。
- コードリファレンス
例外・警告の公式説明 ↗
定義・説明 · 解決手順ではありません
- 一般的な診断ガイド
例外のトレースバックの読み方と対処 ↗
製品全般 · このコード専用ではありません
出典・利用条件
Built-in Exceptions — Python 3.15.2 documentation ↗
著作者: Python Software Foundation
ライセンス: Python Software Foundation License Version 2
確認日: 2026-11-12
変更内容: English prose extracted; whitespace normalized; Korean context and classified official links added. Python code examples not redistributed. 翻訳された説明には、自動翻訳であることを表示しています。