Coverage for mfutil/exc.py: 25%

8 statements  

« 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. 

3 

4 Very interesting reading about exceptions in Python: 

5 https://julien.danjou.info/python-exceptions-guide/ 

6 

7 Usage example: 

8 

9 ```python 

10 from mfutil import MFUtilException 

11 

12 try: 

13 1/0 

14 except Exception as e: 

15 raise MFUtilException("something was wrong", original_exception=e) 

16 ``` 

17 

18 Output example: 

19 ``` 

20 [...] 

21 mfutil.exc.MFUtilException: something was wrong: division by zero 

22 ``` 

23 

24 """ 

25 

26 def __init__(self, msg=None, original_exception=None, **kwargs): 

27 """ 

28 

29 Args: 

30 msg (string): a custom message for this exception. 

31 original_exception (Exception): an Exception object to wrap. 

32 

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)