[Tutor] finally without try or except
Marc Tompkins
marc.tompkins at gmail.com
Mon Jul 30 19:16:22 CEST 2012
On Mon, Jul 30, 2012 at 9:56 AM, Tino Dai <oberoc at gmail.com> wrote:
> Hi!
>
> Is there anyway to execute a block of code at the end of a program in
> 2.6 regardless of what happened before eg exiting normally or died because
> of an exception?
> I was thinking about maybe a free standing finally code block or a
> decorator.
>
How about calling the entire program in a module and putting the call to it
inside a try/except block? Then you can have your cleanup code in a
finally block at the end of all that.
Exceptions are meant to be caught. I think what you're asking is "is there
any way to make Python ignore any bad stuff and keep running my program?"
The answer is yes: catch your exceptions.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120730/59422048/attachment.html>
More information about the Tutor
mailing list