Coverage for pyTooling/Exceptions/__init__.py: 100%
26 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-25 22:22 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-25 22:22 +0000
1# ==================================================================================================================== #
2# #
3# _____ _ _ _____ _ _ #
4# _ __ _ |_ _|__ ___ | (_)_ __ __ _ | ____|_ _____ ___ _ __ | |_(_) ___ _ __ ___ #
5# | '_ \| | | || |/ _ \ / _ \| | | '_ \ / _` | | _| \ \/ / __/ _ \ '_ \| __| |/ _ \| '_ \/ __| #
6# | |_) | |_| || | (_) | (_) | | | | | | (_| |_| |___ > < (_| __/ |_) | |_| | (_) | | | \__ \ #
7# | .__/ \__, ||_|\___/ \___/|_|_|_| |_|\__, (_)_____/_/\_\___\___| .__/ \__|_|\___/|_| |_|___/ #
8# |_| |___/ |___/ |_| #
9# ==================================================================================================================== #
10# Authors: #
11# Patrick Lehmann #
12# #
13# License: #
14# ==================================================================================================================== #
15# Copyright 2017-2025 Patrick Lehmann - Bötzingen, Germany #
16# #
17# Licensed under the Apache License, Version 2.0 (the "License"); #
18# you may not use this file except in compliance with the License. #
19# You may obtain a copy of the License at #
20# #
21# http://www.apache.org/licenses/LICENSE-2.0 #
22# #
23# Unless required by applicable law or agreed to in writing, software #
24# distributed under the License is distributed on an "AS IS" BASIS, #
25# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
26# See the License for the specific language governing permissions and #
27# limitations under the License. #
28# #
29# SPDX-License-Identifier: Apache-2.0 #
30# ==================================================================================================================== #
31#
32"""
33A common set of missing exceptions in Python.
35.. hint:: See :ref:`high-level help <EXECPTION>` for explanations and usage examples.
36"""
37from sys import version_info
38from typing import List
40try:
41 from pyTooling.Decorators import export
42except (ImportError, ModuleNotFoundError): # pragma: no cover
43 print("[pyTooling.Exceptions] Could not import from 'pyTooling.*'!")
45 try:
46 from Decorators import export
47 except (ImportError, ModuleNotFoundError) as ex: # pragma: no cover
48 print("[pyTooling.Exceptions] Could not import from 'Decorators' directly!")
49 raise ex
52@export
53class OverloadResolutionError(Exception):
54 """
55 The exception is raised, when no matching overloaded method was found.
57 .. seealso::
59 :func:`@overloadable <pyTooling.MetaClasses.overloadable>`
60 |rarr| Mark a method as *overloadable*.
61 """
62 # WORKAROUND: for Python <3.11
63 # Implementing a dummy method for Python versions before
64 __notes__: List[str]
65 if version_info < (3, 11): # pragma: no cover
66 def add_note(self, message: str):
67 try:
68 self.__notes__.append(message)
69 except AttributeError:
70 self.__notes__ = [message]
73@export
74class ExceptionBase(Exception):
75 """Base exception derived from :exc:`Exception <python:Exception>` for all custom exceptions."""
77 def __init__(self, message: str = "") -> None:
78 """
79 ExceptionBase initializer.
81 :param message: The exception message.
82 """
83 super().__init__()
84 self.message = message
86 # WORKAROUND: for Python <3.11
87 # Implementing a dummy method for Python versions before
88 __notes__: List[str]
89 if version_info < (3, 11): # pragma: no cover
90 def add_note(self, message: str):
91 try:
92 self.__notes__.append(message)
93 except AttributeError:
94 self.__notes__ = [message]
96 def __str__(self) -> str:
97 """Returns the exception's message text."""
98 return self.message
100 def with_traceback(self, tb) -> None:
101 super().with_traceback(tb)
103 # @DocumentMemberAttribute(False)
104 # @MethodAlias(pyExceptions.with_traceback)
105 # def with_traceback(self): pass
108@export
109class EnvironmentException(ExceptionBase):
110 """The exception is raised when an expected environment variable is missing."""
113@export
114class PlatformNotSupportedException(ExceptionBase):
115 """The exception is raise if the platform is not supported."""
118@export
119class NotConfiguredException(ExceptionBase):
120 """The exception is raise if the requested setting is not configured."""
123@export
124class ToolingException(Exception):
125 """The exception is raised by pyTooling internal features."""
127 # WORKAROUND: for Python <3.11
128 # Implementing a dummy method for Python versions before
129 __notes__: List[str]
130 if version_info < (3, 11): # pragma: no cover
131 def add_note(self, message: str):
132 try:
133 self.__notes__.append(message)
134 except AttributeError:
135 self.__notes__ = [message]