I need to return True Value after raise statement. Here I need to raise statement as well as it should return True value. If I use finally statement, it will not raise exception block and if I do not use finally then exception block will execute with raise statement and after that I will not able to use retcodecmd variable. Below My Code in python:
try:
something....
except ValueError:
self._retcodecmd = True
raise SomeException(something)
finally:
if self._retcodecmd is True:
return True
else:
return False
Returning and bubbling exceptions out of a function are mutually exclusive. It's nonsensical to exit a function by both raise
and return
, you have to choose.
The finally
block here will force a return
, undoing the exception you raised. If that's not what you want, you need to let the exception propagate without being overridden in the finally
block and understand how to handle the exception appropriately in a caller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With