Skip to content

base

Classes:

CatchError

CatchError(error: type[CustomErrorT])

Bases: AbstractContextManager['CatchError[CustomErrorT]']

Context manager for catching a specific exception type.

Attributes:

  • error (CustomErrorT | None) –

    The caught exception instance, if any.

  • tb (TracebackType | None) –

    The traceback object associated with the caught exception.

Source code in jetpytools/exceptions/base.py
156
157
158
159
def __init__(self, error: type[CustomErrorT]) -> None:
    self.error = None
    self.tb = None
    self._to_catch_error = error

error instance-attribute

error: CustomErrorT | None = None

The caught exception instance, if any.

tb instance-attribute

tb: TracebackType | None = None

The traceback object associated with the caught exception.

CustomError

CustomError(
    message: SupportsString | None = None,
    func: FuncExcept | None = None,
    reason: Any = None,
    **kwargs: Any
)

Bases: Exception

Custom base exception class.

Instantiate a new exception with pretty printing and more.

Parameters:

  • message

    (SupportsString | None, default: None ) –

    Message of the error.

  • func

    (FuncExcept | None, default: None ) –

    Function this exception was raised from.

  • reason

    (Any, default: None ) –

    Reason of the exception. For example, an optional parameter.

Methods:

  • __call__

    Copy an existing exception with defaults and instantiate a new one.

  • catch

    Create a context manager that catches exceptions of this class type.

Attributes:

Source code in jetpytools/exceptions/base.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
def __init__(
    self, message: SupportsString | None = None, func: FuncExcept | None = None, reason: Any = None, **kwargs: Any
) -> None:
    """
    Instantiate a new exception with pretty printing and more.

    Args:
        message: Message of the error.
        func: Function this exception was raised from.
        reason: Reason of the exception. For example, an optional parameter.
    """

    self.message = message
    self.func = func
    self.reason = reason
    self.kwargs = kwargs

    super().__init__(message)

func instance-attribute

func = func

kwargs instance-attribute

kwargs = kwargs

message instance-attribute

message = message

reason instance-attribute

reason = reason

__call__

__call__(
    message: SupportsString | None | MissingT = MISSING,
    func: FuncExcept | None | MissingT = MISSING,
    reason: SupportsString | FuncExcept | None | MissingT = MISSING,
    **kwargs: Any
) -> Self

Copy an existing exception with defaults and instantiate a new one.

Parameters:

Source code in jetpytools/exceptions/base.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
def __call__(
    self,
    message: SupportsString | None | MissingT = MISSING,
    func: FuncExcept | None | MissingT = MISSING,
    reason: SupportsString | FuncExcept | None | MissingT = MISSING,
    **kwargs: Any,
) -> Self:
    """
    Copy an existing exception with defaults and instantiate a new one.

    Args:
        message: Message of the error.
        func: Function this exception was raised from.
        reason: Reason of the exception. For example, an optional parameter.
    """
    from copy import deepcopy

    err = deepcopy(self)

    if message is not MISSING:
        err.message = message

    if func is not MISSING:
        err.func = func

    if reason is not MISSING:
        err.reason = reason

    err.kwargs |= kwargs

    return err

catch classmethod

catch() -> CatchError[Self]

Create a context manager that catches exceptions of this class type.

Returns:

  • CatchError[Self]

    CatchError[Self]: A context manager that will catch and store exceptions of type cls when used in a with block.

Source code in jetpytools/exceptions/base.py
134
135
136
137
138
139
140
141
142
143
@classmethod
def catch(cls) -> CatchError[Self]:
    """
    Create a context manager that catches exceptions of this class type.

    Returns:
        CatchError[Self]: A context manager that will catch and store exceptions of type `cls`
            when used in a `with` block.
    """
    return CatchError(cls)

CustomErrorMeta

Bases: type

Custom base exception meta class.

CustomIndexError

CustomIndexError(
    message: SupportsString | None = None,
    func: FuncExcept | None = None,
    reason: Any = None,
    **kwargs: Any
)

Bases: CustomError, IndexError

Thrown when an index or generic numeric value is out of bound.

Instantiate a new exception with pretty printing and more.

Parameters:

  • message

    (SupportsString | None, default: None ) –

    Message of the error.

  • func

    (FuncExcept | None, default: None ) –

    Function this exception was raised from.

  • reason

    (Any, default: None ) –

    Reason of the exception. For example, an optional parameter.

Methods:

  • __call__

    Copy an existing exception with defaults and instantiate a new one.

  • catch

    Create a context manager that catches exceptions of this class type.

Attributes:

Source code in jetpytools/exceptions/base.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
def __init__(
    self, message: SupportsString | None = None, func: FuncExcept | None = None, reason: Any = None, **kwargs: Any
) -> None:
    """
    Instantiate a new exception with pretty printing and more.

    Args:
        message: Message of the error.
        func: Function this exception was raised from.
        reason: Reason of the exception. For example, an optional parameter.
    """

    self.message = message
    self.func = func
    self.reason = reason
    self.kwargs = kwargs

    super().__init__(message)

func instance-attribute

func = func

kwargs instance-attribute

kwargs = kwargs

message instance-attribute

message = message

reason instance-attribute

reason = reason

__call__

__call__(
    message: SupportsString | None | MissingT = MISSING,
    func: FuncExcept | None | MissingT = MISSING,
    reason: SupportsString | FuncExcept | None | MissingT = MISSING,
    **kwargs: Any
) -> Self

Copy an existing exception with defaults and instantiate a new one.

Parameters:

Source code in jetpytools/exceptions/base.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
def __call__(
    self,
    message: SupportsString | None | MissingT = MISSING,
    func: FuncExcept | None | MissingT = MISSING,
    reason: SupportsString | FuncExcept | None | MissingT = MISSING,
    **kwargs: Any,
) -> Self:
    """
    Copy an existing exception with defaults and instantiate a new one.

    Args:
        message: Message of the error.
        func: Function this exception was raised from.
        reason: Reason of the exception. For example, an optional parameter.
    """
    from copy import deepcopy

    err = deepcopy(self)

    if message is not MISSING:
        err.message = message

    if func is not MISSING:
        err.func = func

    if reason is not MISSING:
        err.reason = reason

    err.kwargs |= kwargs

    return err

catch classmethod

catch() -> CatchError[Self]

Create a context manager that catches exceptions of this class type.

Returns:

  • CatchError[Self]

    CatchError[Self]: A context manager that will catch and store exceptions of type cls when used in a with block.

Source code in jetpytools/exceptions/base.py
134
135
136
137
138
139
140
141
142
143
@classmethod
def catch(cls) -> CatchError[Self]:
    """
    Create a context manager that catches exceptions of this class type.

    Returns:
        CatchError[Self]: A context manager that will catch and store exceptions of type `cls`
            when used in a `with` block.
    """
    return CatchError(cls)

CustomKeyError

CustomKeyError(
    message: SupportsString | None = None,
    func: FuncExcept | None = None,
    reason: Any = None,
    **kwargs: Any
)

Bases: CustomError, KeyError

Thrown when trying to access an non-existent key.

Instantiate a new exception with pretty printing and more.

Parameters:

  • message

    (SupportsString | None, default: None ) –

    Message of the error.

  • func

    (FuncExcept | None, default: None ) –

    Function this exception was raised from.

  • reason

    (Any, default: None ) –

    Reason of the exception. For example, an optional parameter.

Methods:

  • __call__

    Copy an existing exception with defaults and instantiate a new one.

  • catch

    Create a context manager that catches exceptions of this class type.

Attributes:

Source code in jetpytools/exceptions/base.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
def __init__(
    self, message: SupportsString | None = None, func: FuncExcept | None = None, reason: Any = None, **kwargs: Any
) -> None:
    """
    Instantiate a new exception with pretty printing and more.

    Args:
        message: Message of the error.
        func: Function this exception was raised from.
        reason: Reason of the exception. For example, an optional parameter.
    """

    self.message = message
    self.func = func
    self.reason = reason
    self.kwargs = kwargs

    super().__init__(message)

func instance-attribute

func = func

kwargs instance-attribute

kwargs = kwargs

message instance-attribute

message = message

reason instance-attribute

reason = reason

__call__

__call__(
    message: SupportsString | None | MissingT = MISSING,
    func: FuncExcept | None | MissingT = MISSING,
    reason: SupportsString | FuncExcept | None | MissingT = MISSING,
    **kwargs: Any
) -> Self

Copy an existing exception with defaults and instantiate a new one.

Parameters:

Source code in jetpytools/exceptions/base.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
def __call__(
    self,
    message: SupportsString | None | MissingT = MISSING,
    func: FuncExcept | None | MissingT = MISSING,
    reason: SupportsString | FuncExcept | None | MissingT = MISSING,
    **kwargs: Any,
) -> Self:
    """
    Copy an existing exception with defaults and instantiate a new one.

    Args:
        message: Message of the error.
        func: Function this exception was raised from.
        reason: Reason of the exception. For example, an optional parameter.
    """
    from copy import deepcopy

    err = deepcopy(self)

    if message is not MISSING:
        err.message = message

    if func is not MISSING:
        err.func = func

    if reason is not MISSING:
        err.reason = reason

    err.kwargs |= kwargs

    return err

catch classmethod

catch() -> CatchError[Self]

Create a context manager that catches exceptions of this class type.

Returns:

  • CatchError[Self]

    CatchError[Self]: A context manager that will catch and store exceptions of type cls when used in a with block.

Source code in jetpytools/exceptions/base.py
134
135
136
137
138
139
140
141
142
143
@classmethod
def catch(cls) -> CatchError[Self]:
    """
    Create a context manager that catches exceptions of this class type.

    Returns:
        CatchError[Self]: A context manager that will catch and store exceptions of type `cls`
            when used in a `with` block.
    """
    return CatchError(cls)

CustomNotImplementedError

CustomNotImplementedError(
    message: SupportsString | None = None,
    func: FuncExcept | None = None,
    reason: Any = None,
    **kwargs: Any
)

Bases: CustomError, NotImplementedError

Thrown when you encounter a yet not implemented branch of code.

Instantiate a new exception with pretty printing and more.

Parameters:

  • message

    (SupportsString | None, default: None ) –

    Message of the error.

  • func

    (FuncExcept | None, default: None ) –

    Function this exception was raised from.

  • reason

    (Any, default: None ) –

    Reason of the exception. For example, an optional parameter.

Methods:

  • __call__

    Copy an existing exception with defaults and instantiate a new one.

  • catch

    Create a context manager that catches exceptions of this class type.

Attributes:

Source code in jetpytools/exceptions/base.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
def __init__(
    self, message: SupportsString | None = None, func: FuncExcept | None = None, reason: Any = None, **kwargs: Any
) -> None:
    """
    Instantiate a new exception with pretty printing and more.

    Args:
        message: Message of the error.
        func: Function this exception was raised from.
        reason: Reason of the exception. For example, an optional parameter.
    """

    self.message = message
    self.func = func
    self.reason = reason
    self.kwargs = kwargs

    super().__init__(message)

func instance-attribute

func = func

kwargs instance-attribute

kwargs = kwargs

message instance-attribute

message = message

reason instance-attribute

reason = reason

__call__

__call__(
    message: SupportsString | None | MissingT = MISSING,
    func: FuncExcept | None | MissingT = MISSING,
    reason: SupportsString | FuncExcept | None | MissingT = MISSING,
    **kwargs: Any
) -> Self

Copy an existing exception with defaults and instantiate a new one.

Parameters:

Source code in jetpytools/exceptions/base.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
def __call__(
    self,
    message: SupportsString | None | MissingT = MISSING,
    func: FuncExcept | None | MissingT = MISSING,
    reason: SupportsString | FuncExcept | None | MissingT = MISSING,
    **kwargs: Any,
) -> Self:
    """
    Copy an existing exception with defaults and instantiate a new one.

    Args:
        message: Message of the error.
        func: Function this exception was raised from.
        reason: Reason of the exception. For example, an optional parameter.
    """
    from copy import deepcopy

    err = deepcopy(self)

    if message is not MISSING:
        err.message = message

    if func is not MISSING:
        err.func = func

    if reason is not MISSING:
        err.reason = reason

    err.kwargs |= kwargs

    return err

catch classmethod

catch() -> CatchError[Self]

Create a context manager that catches exceptions of this class type.

Returns:

  • CatchError[Self]

    CatchError[Self]: A context manager that will catch and store exceptions of type cls when used in a with block.

Source code in jetpytools/exceptions/base.py
134
135
136
137
138
139
140
141
142
143
@classmethod
def catch(cls) -> CatchError[Self]:
    """
    Create a context manager that catches exceptions of this class type.

    Returns:
        CatchError[Self]: A context manager that will catch and store exceptions of type `cls`
            when used in a `with` block.
    """
    return CatchError(cls)

CustomOverflowError

CustomOverflowError(
    message: SupportsString | None = None,
    func: FuncExcept | None = None,
    reason: Any = None,
    **kwargs: Any
)

Bases: CustomError, OverflowError

Thrown when a value is out of range. e.g. temporal radius too big.

Instantiate a new exception with pretty printing and more.

Parameters:

  • message

    (SupportsString | None, default: None ) –

    Message of the error.

  • func

    (FuncExcept | None, default: None ) –

    Function this exception was raised from.

  • reason

    (Any, default: None ) –

    Reason of the exception. For example, an optional parameter.

Methods:

  • __call__

    Copy an existing exception with defaults and instantiate a new one.

  • catch

    Create a context manager that catches exceptions of this class type.

Attributes:

Source code in jetpytools/exceptions/base.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
def __init__(
    self, message: SupportsString | None = None, func: FuncExcept | None = None, reason: Any = None, **kwargs: Any
) -> None:
    """
    Instantiate a new exception with pretty printing and more.

    Args:
        message: Message of the error.
        func: Function this exception was raised from.
        reason: Reason of the exception. For example, an optional parameter.
    """

    self.message = message
    self.func = func
    self.reason = reason
    self.kwargs = kwargs

    super().__init__(message)

func instance-attribute

func = func

kwargs instance-attribute

kwargs = kwargs

message instance-attribute

message = message

reason instance-attribute

reason = reason

__call__

__call__(
    message: SupportsString | None | MissingT = MISSING,
    func: FuncExcept | None | MissingT = MISSING,
    reason: SupportsString | FuncExcept | None | MissingT = MISSING,
    **kwargs: Any
) -> Self

Copy an existing exception with defaults and instantiate a new one.

Parameters:

Source code in jetpytools/exceptions/base.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
def __call__(
    self,
    message: SupportsString | None | MissingT = MISSING,
    func: FuncExcept | None | MissingT = MISSING,
    reason: SupportsString | FuncExcept | None | MissingT = MISSING,
    **kwargs: Any,
) -> Self:
    """
    Copy an existing exception with defaults and instantiate a new one.

    Args:
        message: Message of the error.
        func: Function this exception was raised from.
        reason: Reason of the exception. For example, an optional parameter.
    """
    from copy import deepcopy

    err = deepcopy(self)

    if message is not MISSING:
        err.message = message

    if func is not MISSING:
        err.func = func

    if reason is not MISSING:
        err.reason = reason

    err.kwargs |= kwargs

    return err

catch classmethod

catch() -> CatchError[Self]

Create a context manager that catches exceptions of this class type.

Returns:

  • CatchError[Self]

    CatchError[Self]: A context manager that will catch and store exceptions of type cls when used in a with block.

Source code in jetpytools/exceptions/base.py
134
135
136
137
138
139
140
141
142
143
@classmethod
def catch(cls) -> CatchError[Self]:
    """
    Create a context manager that catches exceptions of this class type.

    Returns:
        CatchError[Self]: A context manager that will catch and store exceptions of type `cls`
            when used in a `with` block.
    """
    return CatchError(cls)

CustomPermissionError

CustomPermissionError(
    message: SupportsString | None = None,
    func: FuncExcept | None = None,
    reason: Any = None,
    **kwargs: Any
)

Bases: CustomError, PermissionError

Thrown when the user can't perform an action.

Instantiate a new exception with pretty printing and more.

Parameters:

  • message

    (SupportsString | None, default: None ) –

    Message of the error.

  • func

    (FuncExcept | None, default: None ) –

    Function this exception was raised from.

  • reason

    (Any, default: None ) –

    Reason of the exception. For example, an optional parameter.

Methods:

  • __call__

    Copy an existing exception with defaults and instantiate a new one.

  • catch

    Create a context manager that catches exceptions of this class type.

Attributes:

Source code in jetpytools/exceptions/base.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
def __init__(
    self, message: SupportsString | None = None, func: FuncExcept | None = None, reason: Any = None, **kwargs: Any
) -> None:
    """
    Instantiate a new exception with pretty printing and more.

    Args:
        message: Message of the error.
        func: Function this exception was raised from.
        reason: Reason of the exception. For example, an optional parameter.
    """

    self.message = message
    self.func = func
    self.reason = reason
    self.kwargs = kwargs

    super().__init__(message)

func instance-attribute

func = func

kwargs instance-attribute

kwargs = kwargs

message instance-attribute

message = message

reason instance-attribute

reason = reason

__call__

__call__(
    message: SupportsString | None | MissingT = MISSING,
    func: FuncExcept | None | MissingT = MISSING,
    reason: SupportsString | FuncExcept | None | MissingT = MISSING,
    **kwargs: Any
) -> Self

Copy an existing exception with defaults and instantiate a new one.

Parameters:

Source code in jetpytools/exceptions/base.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
def __call__(
    self,
    message: SupportsString | None | MissingT = MISSING,
    func: FuncExcept | None | MissingT = MISSING,
    reason: SupportsString | FuncExcept | None | MissingT = MISSING,
    **kwargs: Any,
) -> Self:
    """
    Copy an existing exception with defaults and instantiate a new one.

    Args:
        message: Message of the error.
        func: Function this exception was raised from.
        reason: Reason of the exception. For example, an optional parameter.
    """
    from copy import deepcopy

    err = deepcopy(self)

    if message is not MISSING:
        err.message = message

    if func is not MISSING:
        err.func = func

    if reason is not MISSING:
        err.reason = reason

    err.kwargs |= kwargs

    return err

catch classmethod

catch() -> CatchError[Self]

Create a context manager that catches exceptions of this class type.

Returns:

  • CatchError[Self]

    CatchError[Self]: A context manager that will catch and store exceptions of type cls when used in a with block.

Source code in jetpytools/exceptions/base.py
134
135
136
137
138
139
140
141
142
143
@classmethod
def catch(cls) -> CatchError[Self]:
    """
    Create a context manager that catches exceptions of this class type.

    Returns:
        CatchError[Self]: A context manager that will catch and store exceptions of type `cls`
            when used in a `with` block.
    """
    return CatchError(cls)

CustomRuntimeError

CustomRuntimeError(
    message: SupportsString | None = None,
    func: FuncExcept | None = None,
    reason: Any = None,
    **kwargs: Any
)

Bases: CustomError, RuntimeError

Thrown when a runtime error occurs.

Instantiate a new exception with pretty printing and more.

Parameters:

  • message

    (SupportsString | None, default: None ) –

    Message of the error.

  • func

    (FuncExcept | None, default: None ) –

    Function this exception was raised from.

  • reason

    (Any, default: None ) –

    Reason of the exception. For example, an optional parameter.

Methods:

  • __call__

    Copy an existing exception with defaults and instantiate a new one.

  • catch

    Create a context manager that catches exceptions of this class type.

Attributes:

Source code in jetpytools/exceptions/base.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
def __init__(
    self, message: SupportsString | None = None, func: FuncExcept | None = None, reason: Any = None, **kwargs: Any
) -> None:
    """
    Instantiate a new exception with pretty printing and more.

    Args:
        message: Message of the error.
        func: Function this exception was raised from.
        reason: Reason of the exception. For example, an optional parameter.
    """

    self.message = message
    self.func = func
    self.reason = reason
    self.kwargs = kwargs

    super().__init__(message)

func instance-attribute

func = func

kwargs instance-attribute

kwargs = kwargs

message instance-attribute

message = message

reason instance-attribute

reason = reason

__call__

__call__(
    message: SupportsString | None | MissingT = MISSING,
    func: FuncExcept | None | MissingT = MISSING,
    reason: SupportsString | FuncExcept | None | MissingT = MISSING,
    **kwargs: Any
) -> Self

Copy an existing exception with defaults and instantiate a new one.

Parameters:

Source code in jetpytools/exceptions/base.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
def __call__(
    self,
    message: SupportsString | None | MissingT = MISSING,
    func: FuncExcept | None | MissingT = MISSING,
    reason: SupportsString | FuncExcept | None | MissingT = MISSING,
    **kwargs: Any,
) -> Self:
    """
    Copy an existing exception with defaults and instantiate a new one.

    Args:
        message: Message of the error.
        func: Function this exception was raised from.
        reason: Reason of the exception. For example, an optional parameter.
    """
    from copy import deepcopy

    err = deepcopy(self)

    if message is not MISSING:
        err.message = message

    if func is not MISSING:
        err.func = func

    if reason is not MISSING:
        err.reason = reason

    err.kwargs |= kwargs

    return err

catch classmethod

catch() -> CatchError[Self]

Create a context manager that catches exceptions of this class type.

Returns:

  • CatchError[Self]

    CatchError[Self]: A context manager that will catch and store exceptions of type cls when used in a with block.

Source code in jetpytools/exceptions/base.py
134
135
136
137
138
139
140
141
142
143
@classmethod
def catch(cls) -> CatchError[Self]:
    """
    Create a context manager that catches exceptions of this class type.

    Returns:
        CatchError[Self]: A context manager that will catch and store exceptions of type `cls`
            when used in a `with` block.
    """
    return CatchError(cls)

CustomTypeError

CustomTypeError(
    message: SupportsString | None = None,
    func: FuncExcept | None = None,
    reason: Any = None,
    **kwargs: Any
)

Bases: CustomError, TypeError

Thrown when a passed argument is of wrong type.

Instantiate a new exception with pretty printing and more.

Parameters:

  • message

    (SupportsString | None, default: None ) –

    Message of the error.

  • func

    (FuncExcept | None, default: None ) –

    Function this exception was raised from.

  • reason

    (Any, default: None ) –

    Reason of the exception. For example, an optional parameter.

Methods:

  • __call__

    Copy an existing exception with defaults and instantiate a new one.

  • catch

    Create a context manager that catches exceptions of this class type.

Attributes:

Source code in jetpytools/exceptions/base.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
def __init__(
    self, message: SupportsString | None = None, func: FuncExcept | None = None, reason: Any = None, **kwargs: Any
) -> None:
    """
    Instantiate a new exception with pretty printing and more.

    Args:
        message: Message of the error.
        func: Function this exception was raised from.
        reason: Reason of the exception. For example, an optional parameter.
    """

    self.message = message
    self.func = func
    self.reason = reason
    self.kwargs = kwargs

    super().__init__(message)

func instance-attribute

func = func

kwargs instance-attribute

kwargs = kwargs

message instance-attribute

message = message

reason instance-attribute

reason = reason

__call__

__call__(
    message: SupportsString | None | MissingT = MISSING,
    func: FuncExcept | None | MissingT = MISSING,
    reason: SupportsString | FuncExcept | None | MissingT = MISSING,
    **kwargs: Any
) -> Self

Copy an existing exception with defaults and instantiate a new one.

Parameters:

Source code in jetpytools/exceptions/base.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
def __call__(
    self,
    message: SupportsString | None | MissingT = MISSING,
    func: FuncExcept | None | MissingT = MISSING,
    reason: SupportsString | FuncExcept | None | MissingT = MISSING,
    **kwargs: Any,
) -> Self:
    """
    Copy an existing exception with defaults and instantiate a new one.

    Args:
        message: Message of the error.
        func: Function this exception was raised from.
        reason: Reason of the exception. For example, an optional parameter.
    """
    from copy import deepcopy

    err = deepcopy(self)

    if message is not MISSING:
        err.message = message

    if func is not MISSING:
        err.func = func

    if reason is not MISSING:
        err.reason = reason

    err.kwargs |= kwargs

    return err

catch classmethod

catch() -> CatchError[Self]

Create a context manager that catches exceptions of this class type.

Returns:

  • CatchError[Self]

    CatchError[Self]: A context manager that will catch and store exceptions of type cls when used in a with block.

Source code in jetpytools/exceptions/base.py
134
135
136
137
138
139
140
141
142
143
@classmethod
def catch(cls) -> CatchError[Self]:
    """
    Create a context manager that catches exceptions of this class type.

    Returns:
        CatchError[Self]: A context manager that will catch and store exceptions of type `cls`
            when used in a `with` block.
    """
    return CatchError(cls)

CustomValueError

CustomValueError(
    message: SupportsString | None = None,
    func: FuncExcept | None = None,
    reason: Any = None,
    **kwargs: Any
)

Bases: CustomError, ValueError

Thrown when a specified value is invalid.

Instantiate a new exception with pretty printing and more.

Parameters:

  • message

    (SupportsString | None, default: None ) –

    Message of the error.

  • func

    (FuncExcept | None, default: None ) –

    Function this exception was raised from.

  • reason

    (Any, default: None ) –

    Reason of the exception. For example, an optional parameter.

Methods:

  • __call__

    Copy an existing exception with defaults and instantiate a new one.

  • catch

    Create a context manager that catches exceptions of this class type.

Attributes:

Source code in jetpytools/exceptions/base.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
def __init__(
    self, message: SupportsString | None = None, func: FuncExcept | None = None, reason: Any = None, **kwargs: Any
) -> None:
    """
    Instantiate a new exception with pretty printing and more.

    Args:
        message: Message of the error.
        func: Function this exception was raised from.
        reason: Reason of the exception. For example, an optional parameter.
    """

    self.message = message
    self.func = func
    self.reason = reason
    self.kwargs = kwargs

    super().__init__(message)

func instance-attribute

func = func

kwargs instance-attribute

kwargs = kwargs

message instance-attribute

message = message

reason instance-attribute

reason = reason

__call__

__call__(
    message: SupportsString | None | MissingT = MISSING,
    func: FuncExcept | None | MissingT = MISSING,
    reason: SupportsString | FuncExcept | None | MissingT = MISSING,
    **kwargs: Any
) -> Self

Copy an existing exception with defaults and instantiate a new one.

Parameters:

Source code in jetpytools/exceptions/base.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
def __call__(
    self,
    message: SupportsString | None | MissingT = MISSING,
    func: FuncExcept | None | MissingT = MISSING,
    reason: SupportsString | FuncExcept | None | MissingT = MISSING,
    **kwargs: Any,
) -> Self:
    """
    Copy an existing exception with defaults and instantiate a new one.

    Args:
        message: Message of the error.
        func: Function this exception was raised from.
        reason: Reason of the exception. For example, an optional parameter.
    """
    from copy import deepcopy

    err = deepcopy(self)

    if message is not MISSING:
        err.message = message

    if func is not MISSING:
        err.func = func

    if reason is not MISSING:
        err.reason = reason

    err.kwargs |= kwargs

    return err

catch classmethod

catch() -> CatchError[Self]

Create a context manager that catches exceptions of this class type.

Returns:

  • CatchError[Self]

    CatchError[Self]: A context manager that will catch and store exceptions of type cls when used in a with block.

Source code in jetpytools/exceptions/base.py
134
135
136
137
138
139
140
141
142
143
@classmethod
def catch(cls) -> CatchError[Self]:
    """
    Create a context manager that catches exceptions of this class type.

    Returns:
        CatchError[Self]: A context manager that will catch and store exceptions of type `cls`
            when used in a `with` block.
    """
    return CatchError(cls)