Coverage for mfutil/exc.py: 25%
8 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-11-13 15:33 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-11-13 15:33 +0000
1class MFUtilException(Exception):
2 """Generic exception class with a way to wrap original exceptions.
4 Very interesting reading about exceptions in Python:
5 https://julien.danjou.info/python-exceptions-guide/
7 Usage example:
9 ```python
10 from mfutil import MFUtilException
12 try:
13 1/0
14 except Exception as e:
15 raise MFUtilException("something was wrong", original_exception=e)
16 ```
18 Output example:
19 ```
20 [...]
21 mfutil.exc.MFUtilException: something was wrong: division by zero
22 ```
24 """
26 def __init__(self, msg=None, original_exception=None, **kwargs):
27 """
29 Args:
30 msg (string): a custom message for this exception.
31 original_exception (Exception): an Exception object to wrap.
33 """
34 if msg is not None:
35 self.message = msg
36 else:
37 self.message = "mfplugin_exception"
38 if original_exception is not None:
39 Exception.__init__(
40 self, self.message + (": %s" % original_exception), **kwargs
41 )
42 else:
43 Exception.__init__(self, self.message, **kwargs)