I have a python class with many methods():
Method1()
Method2()
………..
………..
MethodN()
All methods — while performing different tasks — have the same scheme:
do something
do something else
has anything gone wrong?
raise an exception
I want to be able to get an email whenever an exception is raised anywhere in the class.
Is there some easy way to combine this logic into the class, rather than calling SendEmail() before every raise Exception statement? what is the right, pythonic way to deal with such a case? canh a ‘generalized’ Exception handler be the solution? I’d be glad for any ideas you may have.
Note: Although this is a simple, obvious solution to the problem as stated, the below answer is probably better in most cases.
If the alternative is this:
Then why don’t you just define a custom
raise_emailmethod?