Skip to content

Panics

Panics represented as errors.

Panic

Bases: AnyError

Represents panics as errors.

Panics should not be explicitly handled in general, therefore Panic is derived from AnyError.

Source code in src/wraps/panics.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class Panic(AnyError):
    """Represents panics as errors.

    Panics should not be explicitly handled in general, therefore [`Panic`][wraps.panics.Panic]
    is derived from [`AnyError`][typing_aliases.AnyError].
    """

    def __init__(self, message: Optional[str] = None) -> None:
        self._message = message

        if message is None:
            message = PANIC

        super().__init__(message)

    @property
    def message(self) -> Optional[str]:
        return self._message

panic(message: Optional[str] = None) -> Never

Panics with the optional message.

Parameters:

Name Type Description Default
message Optional[str]

The message to panic with.

None

Raises:

Type Description
Panic

Always raised.

Source code in src/wraps/panics.py
35
36
37
38
39
40
41
42
43
44
def panic(message: Optional[str] = None) -> Never:
    """Panics with the optional message.

    Arguments:
        message: The message to panic with.

    Raises:
        Panic: Always raised.
    """
    raise Panic(message)