Correct way of getting traceback using python - 'raise from' syntax, when using custom defined exceptions?

Viewed 65

I have defined few custom exceptions and am trying to chain exceptions using raise from

1 ## Example Custom Exception
2 
3 class Error(Exception):
4     """Base class for exceptions in this module."""
5     pass
6 class SQLError(Error):
7 
8     def __init__(self, message):
9         self.message = message
10 
11 ## Example method that throws a pyodbc Exception
12 
13 def update_sql_data(self):
14     try:
15         ... A Sql Update Exception that raises: Pyodbc Exception ...
16 
17     except Exception as e:
18         raise SQLError(message = f"SQL Update Exception") from e

Expecting a traceback that includes pyodbc exception on line 15, but what I get is only,

File "codeblockOnStackOverflow.py", line 18, in update_sql_data
    raise SQLError(message = f"SQL Update Exception") from e SQLError
0 Answers
Related