[Tutor] How much in a "try" block?

Chris Down chris at chrisdown.name
Thu Aug 22 22:27:28 CEST 2013


On 2013-08-23 06:20, Amit Saha wrote:
> On Fri, Aug 23, 2013 at 6:14 AM, leam hall <leamhall at gmail.com> wrote:
> > If I have a series of tasks that depend on X happening, should I put them
> > all in the same "try" block or just put X in there and exit out if it fails?
> 
> You are right about the latter. You should put only the statement
> which you expect to raise the exception.

You can also use the "else" clause if there is stuff you want to run if the try
block doesn't raise the caught exception, which avoids putting it in "try" if
you don't intend to exit from the exception.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20130822/c2f7766e/attachment.sig>


More information about the Tutor mailing list