I was wondering if you can re-raise the (specific) caught exception and catch it later (in general), except for the same try-except. As an example, I want to do something with a specific IOError, but if its not an expected IOError, then the exception should be handled like any other error. I originally tried:
try: raise IOError() except IOError as ioerr: if ioerr.errno == errno.ENOENT:
However, this does not work: a raise repeatedly raises an exception outside the context of try-except. What would be the pythonic way of writing this in order to get the desired โfailureโ exception?
(I know that a "conditional exception" was proposed that was not implemented, which could solve this)
source share