g.nius.ck at gmail.com
Thu Jun 24 15:12:57 CEST 2010
you mean it will always run even if the exception is handled?
On Thu, Jun 24, 2010 at 9:06 AM, Hugo Arts <hugo.yoshi at gmail.com> wrote:
> On Thu, Jun 24, 2010 at 4:36 AM, Christopher King <g.nius.ck at gmail.com>
> > In a try except clause, you can end with finally block. I know it
> > after the try and except blocks regardless of the outcome, but why use
> > Couldn't you just put the code after the try and except block without
> > a finally block. Does the finally command do something I don't know
> > Does it make your program more understandable in some way?
> The thing about the finally block is that it *always* runs. If you
> just put some code after the try: except: clause, it won't run if
> a) the exception is not handled in the try: except: block, but higher
> up in the call stack
> b) the exception is not handled at all
> c) the exception handler terminates the program
> d) the exception handler raises another exception
> If you need to do some cleanup, putting it in a finally block is the
> only way to *guarantee* it will run.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor