Portal de códigos de error
PythonPythonCódigo de error

BaseExceptionGroup

BaseExceptionGroup

Código BaseExceptionGroup · Problema informado por Python.

Ambos tipos de excepción envuelven las excepciones en la secuencia excs. El parámetro msg debe ser una cadena. La diferencia entre las dos clases es que BaseExceptionGroup extiende BaseException y puede envolver cualquier excepción, mientras que ExceptionGroup extiende Exception y solo puede envolver subclases de Exception. Este diseño es para que, excepto Exception, capture un ExceptionGroup pero no un BaseExceptionGroup. El constructor BaseExceptionGroup devuelve un ExceptionGroup en lugar de un BaseExceptionGroup si todas las excepciones contenidas son instancias de Exception, por lo que se puede utilizar para hacer que la selección sea automática. El constructor ExceptionGroup, por otro lado, genera un TypeError si alguna excepción contenida no es una subclase de excepción. Los grupos de excepciones son genéricos en cuanto al tipo de excepciones que contienen. Tenga en cuenta que BaseExceptionGroup define __new__(), por lo que las subclases que necesitan una firma de constructor diferente deben anularla en lugar de __init__(). Por ejemplo, lo siguiente define una subclase de grupo de excepción que acepta un código de salida y construye el mensaje del grupo a partir de él. Al igual que ExceptionGroup, cualquier subclase de BaseExceptionGroup que también sea una subclase de Exception solo puede encapsular instancias de Exception.

Google Translate · Esta es una traducción automática. Consulte el original en inglés para comprobar los términos técnicos y las condiciones aplicables.

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.

Enlaces de solución de problemas y diagnóstico

Compruebe primero que el producto, la versión y el entorno del documento coincidan con su situación.