[Tutor] question about try & except

Hugo González Monteverde hugonz-lists at h-lab.net
Thu Oct 27 05:27:17 CEST 2005


You can catch an error object along with the exception, as in:

     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.


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