File size: 1,023 Bytes
69601d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import sys

class CustomException(Exception):
    def __init__(self, errorMessage):
        """
        Initialize a CustomException with a detailed error message.

        Args:
            errorMessage (str): The error message to be logged.
        """
        super().__init__(errorMessage)
        self.errorMessage = self.errorMessageDetail(errorMessage)

    @staticmethod
    def errorMessageDetail(error):
        """
        Generate a detailed error message.

        Args:
            error: The error object.

        Returns:
            str: A formatted error message including line number and filename.
        """
        _, _, exc_info = sys.exc_info()
        filename = exc_info.tb_frame.f_code.co_filename
        lineno = exc_info.tb_lineno
        errorMessage = "Error encountered in line no [{}], filename : [{}], saying [{}]".format(lineno, filename, error)
        return errorMessage

    def __str__(self) -> str:
        """Return the detailed error message."""
        return self.errorMessage