Multiple Exception Handlers For The Same Exception
I have a code for a function which is called inside another function.(Result of refactoring). So in the called function I have a huge block of try-catch statements as. def Called()
Solution 1:
This won't work as advertised; only the first except A
clause will ever get executed. What you need is either some logic inside the clause to further inspect the exception, or (if the code inside the try
block permits) several try
-except
blocks.
Example of the former approach:
try:
something_that_might_fail()
except A as e:
if e.is_harmless():
passelif e.is_something_we_can_handle():
handle_it()
else:
raise# re-raise in the hope it gets handled further up the stack
Post a Comment for "Multiple Exception Handlers For The Same Exception"