I have a code snippet that I have wrapped in my own decorator. My decorator simply "catches" all exceptions, and then prints them, then re-raises them. However this is causing me an issue when I have multiple functions calling each other, as they're all getting printed. Example:
@error_wrapper
def myFunction(x, y):
return int_div(x, y)
@error_wrapper
def int_div(x, y):
return x//y
As you see from the code above, whenever y is 0, the function would error because of DivisionByZero. Now since both of these functions are wrapped in my error_wrapper, which is basically a decorator that does:
try:
return func(*args, **kwargs)
except Exception as e:
print(e)
raise
The problem here is that the raise is happening in myFunction and in int_div, which is a side effect of wrapping both functions. So what solution I'm satisfied with is instead of raiseing the error again, I would just do a return with no return value, but this would make me lose the traceback, which is necessary for me to debug the code. I have seen the traceback module, and I've tried it, but now the problem I'm facing is the return is returning None, which is not the intended behavior. Any insight on how to tackle this?
pop upa message box that contains the error details to the user, and it's currently popping up twice.