Checking for an exception
Steve D'Aprano
steve+python at pearwood.info
Sat Jun 24 06:31:01 EDT 2017
What's the right/best way to test whether an object is an exception ahead of
time? (That is, without trying to raise from it.)
I have:
return (isinstance(obj, type) and issubclass(obj, BaseException)
or isinstance(obj, BaseException))
Any better ideas?
--
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.
More information about the Python-list
mailing list