[CentralOH] Missing Exceptions?
Eric Floehr
eric at intellovations.com
Tue Dec 13 21:40:50 CET 2011
Since Python is a dynamic language, there is no "compiler enforced"
exception listing, like say with Java. So there is no way to know other
than via method documentation or code inspection.
In cases where you don't know, you can chain multiple except clauses
catching different exceptions if you want different behavior, and the last
one can just be a raw except which acts as a wildcard and catch all
exceptions not previously trapped, like:
try:
...
except:
print "Unexpected error:", sys.exc_info()[0]
raise # (or sys.exit(1) or whatever)
-Eric
On Tue, Dec 13, 2011 at 3:30 PM, <jep200404 at columbus.rr.com> wrote:
> I wrote:
>
> try:
> float(s)
> except (ValueError):
>
> Later I realized that I had missed an exception,
> so the code was updated to:
>
> try:
> float(s)
> except (ValueError, TypeError): # !!! What exception names am I
> missing?
>
> How does one determine what all the relevant exceptions are?
> How does one conclude that the the list of exceptions is complete?
>
> Those questions are general, about all try/except stuff,
> not just my little example.
>
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> http://mail.python.org/mailman/listinfo/centraloh
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/mailman/private/centraloh/attachments/20111213/2d56dcaa/attachment.html>
More information about the CentralOH
mailing list