File size: 643 Bytes
2350624
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import sys

def error_message_detail(error):
    """
    Get exception information
    """
    _, _, exc_info = sys.exc_info()  
    filename = exc_info.tb_frame.f_code.co_filename  
    lineno = exc_info.tb_lineno 
    error_message = "Error encountered in line no [{}], filename : [{}], saying [{}]".format(lineno, filename, error)
    return error_message 

class CustomException(Exception):
    def __init__(self, error_message):
        super().__init__(error_message)  # Call the parent class constructor
        self.error_message = error_message_detail(error_message) 

    def __str__(self) -> str:
        return self.error_message