Download src/custom_exception.py from useifabdelhady/WeatherRainPrediction: direct link, hf CLI and curl.
- Browser
- Download file 745 Bytes
-
https://huggingface.co/spaces/useifabdelhady/WeatherRainPrediction/resolve/main/src/custom_exception.py
- Command line
-
hf download hf://spaces/useifabdelhady/WeatherRainPrediction/src/custom_exception.py
-
curl -L -o custom_exception.py https://huggingface.co/spaces/useifabdelhady/WeatherRainPrediction/resolve/main/src/custom_exception.py
745 Bytes
| import sys | |
| class CustomException(Exception): | |
| def __init__(self, message: str, error_detail: Exception = None): | |
| self.error_message = self.get_detailed_error_message(message, error_detail) | |
| super().__init__(self.error_message) | |
| def get_detailed_error_message(message, error_detail): | |
| """Format the error message with traceback details.""" | |
| _, _, exc_tb = sys.exc_info() | |
| file_name = exc_tb.tb_frame.f_code.co_filename if exc_tb else "Unknown File" | |
| line_number = exc_tb.tb_lineno if exc_tb else "Unknown Line" | |
| return f"{message} | Error: {error_detail} | File: {file_name} | Line: {line_number}" | |
| def __str__(self): | |
| return self.error_message |