[Tutor] question about try & except
nephish
nephish at xit.net
Thu Oct 27 06:15:18 CEST 2005
Thanks Hugo,
Now that i know where to look....
appreciate your help.
-sk
On Wed, 2005-10-26 at 21:27 -0600, Hugo González Monteverde wrote:
> Yes,
>
> You can catch an error object along with the exception, as in:
>
> try:
> fileo = open("nofile")
> except IOError, e:
> print "Alas...", e
>
> As you see, the error object has a string representation equal wo what
> normally the python interpreter prints...
>
> >>>
> Alas... [Errno 2] No such file or directory: 'nofile'
> >>>
>
>
> Hope it helps. It took me originally a long time to know this trick, as
> it's kinda buried in the docs.
>
> Hugo
>
>
> nephish wrote:
> > Hey there,
> > i am writing some (for me) pretty complicated stuff for work that
> > really needs to work.
> > i have looked at exception handling in the Learning Python book.
> > and i am using some try / except statements.
> > the problem is, that even though my script does not crash, i dont know
> > the exact error.
> > is there a parameter that will allow me to use try and except but that
> > will also pring out the traceback statements that python usually does to
> > the terminal?
> >
> > thanks
> >
> > _______________________________________________
> > Tutor maillist - Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
More information about the Tutor
mailing list