Spaces:
Sleeping
Sleeping
Create exception.py
Browse files- src/exception/exception.py +25 -0
src/exception/exception.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
from src.logging import logger
|
| 3 |
+
|
| 4 |
+
class DeliveryTimeException(Exception):
|
| 5 |
+
def __init__(self, error_message, error_details:sys):
|
| 6 |
+
self.error_message=error_message
|
| 7 |
+
|
| 8 |
+
_, _, exc_tb = sys.exc_info()
|
| 9 |
+
|
| 10 |
+
self.lineno=exc_tb.tb_lineno
|
| 11 |
+
self.file_name=exc_tb.tb_frame.f_code.co_filename
|
| 12 |
+
|
| 13 |
+
def __str__(self):
|
| 14 |
+
return "Error occured in python script name [{0}] line number [{1}] error message [{2}]".format(
|
| 15 |
+
self.file_name, self.lineno, str(self.error_message)
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
if __name__=='__main__':
|
| 20 |
+
try:
|
| 21 |
+
logger.logging.info("Enter try block")
|
| 22 |
+
a = 1/0
|
| 23 |
+
print("This will not be printed")
|
| 24 |
+
except Exception as e:
|
| 25 |
+
raise DeliveryTimeException(e, sys)
|