Skip to content

base

CustomExceptionBase dataclass

Bases: BaseException

Base class for custom exceptions to inherit from.

This class itself inherits from Python's Exception class.

Parameters:

Name Type Description Default
msg str

A message to display with the exception

field(default='Custom exception called')
Usage
raise CustomExceptionBase(msg="This is a custom exception")
Source code in src/red_utils/exc/base.py
@dataclass
class CustomExceptionBase(BaseException):
    """Base class for custom exceptions to inherit from.

    This class itself inherits from Python's Exception class.

    Params:
        msg (str): A message to display with the exception

    Usage:
        ``` py linenums="1"

        raise CustomExceptionBase(msg="This is a custom exception")
        ```
    """

    msg: str = field(default="Custom exception called")
    # errors: Any | None = field(default=None)
    # extra: Any | None = field(default=None)

    def __repr__(self):
        repr_str: str = f"{self.msg!r}"

        return repr_str

    def __str__(self):
        return repr(self)