Ignore exceptions

Scott David Daniels Scott.Daniels at Acm.Org
Thu Jan 24 22:30:50 EST 2008


Roger Miller wrote:
> On Jan 24, 11:30 am, Jonathan Gardner <jgard... at jonathangardner.net>
> wrote:
>> ....
> 
>> A few sample good uses of try/except blocks:
>> (1) Do something else if an expected exception occurs.
>> (2) Show a friendly error message when an exception occurs over ...
> I'd add (3) Clean-up handlers.  These don't actually handle the
> problem, they just free resources, close files, etc. before re-
> raising the exception for someone else to worry about.

Ah, but typically these are try/finally blocks.  Many can be dealt
with by context mangers in 2.5 or later -- see with_statement.


--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list