I am trying to catch an expected exception and raise a new customized exception but skip printing the original exception. Here is what I try:
class CustomizeException(Exception):
def __init__(self):
exception_message = "This is the customize exception"
super(Exception, self).__init__()
if __name__ == '__main__':
try:
x = 10 / 0
except ZeroDivisionError as e:
raise CustomizeException()
But the exception printed still has the original one:
Traceback (most recent call last):
File "/Users/qiangyao/workspace/demo_py/exception.py", line 11, in <module>
x = 10 / 0
ZeroDivisionError: division by zero
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/qiangyao/workspace/demo_py/exception.py", line 13, in <module>
raise CustomizeException()
__main__.CustomizeException
What is the correct way for this purpose?