For my exception handling I actually want to have a concept of a finally
statement which is only called when an exception happened (and not like the real finally statement which is called in all cases).
Here is a short sketch:
class ErrorA(Exception):
pass
class ErrorB(Exception):
pass
error_counter = 0
try:
raise ErrorA # or raise ErrorB
except ErrorA:
print('ErrorA')
error_counter += 1
except ErrorB:
print('ErrorB') # some error handling for ErrorB
error_counter += 1
I need to react on every Exception
differently (in this sketch represented by print
)
Is there something more pythonic? For me it looks weird that I need error_counter += 1
in all Exception
cases.