File size: 767 Bytes
2915eb4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import sys
from networksecurity.logging import logger
class NetworkSecurityException(Exception):
    def __init__(self, error_message, error_details:sys):
        self.error_messge = error_message
        _,_,exc_tb = error_details.exc_info()

        self.lineno = exc_tb.tb_lineno
        self.file_name = exc_tb.tb_frame.f_code.co_filename

    def __str__(self):
        return "Error occured in python script name [{0}] line number [{1}] error message [{2}]".format(
            self.file_name, self.lineno, str(self.error_messge))

if __name__ == "__main__":
    try:
        logger.logging.info("try block chal gaya")
        a=1/0
        print("Chal gaya toh print nahi hona chahiye")
    except Exception as e:
        raise NetworkSecurityException(e, sys)