Re: printing error message from an Exception

2010-12-10 Thread Jean-Michel Pichavant
mark jason wrote: On Dec 10, 11:55 am, Steven D'Aprano wrote: # By the way, IOError is not the only exception you could see. thanks for the help Steven. Is it OK to catch Exception instead of IOError ? In some operation which can cause many errors ,can I use the following? try:

Re: printing error message from an Exception

2010-12-10 Thread Peter Otten
mark jason wrote: > hi > I was trying out some file operations and was trying to open a non > existing file as below > > def do_work(filename): > try: > f = open(filename,"r"); > print 'opened' > except IOError, e: > print 'failed',e.message > finally: >

Re: printing error message from an Exception

2010-12-10 Thread mark jason
On Dec 10, 11:55 am, Steven D'Aprano wrote: >     # By the way, IOError is not the only exception you could see. thanks for the help Steven. Is it OK to catch Exception instead of IOError ? In some operation which can cause many errors ,can I use the following? try: do_something() except Ex

Re: printing error message from an Exception

2010-12-09 Thread Steven D'Aprano
On Thu, 09 Dec 2010 22:16:17 -0800, mark jason wrote: > hi > I was trying out some file operations and was trying to open a non > existing file as below > > def do_work(filename): > try: > f = open(filename,"r"); > print 'opened' > except IOError, e: > print 'faile

printing error message from an Exception

2010-12-09 Thread mark jason
hi I was trying out some file operations and was trying to open a non existing file as below def do_work(filename): try: f = open(filename,"r"); print 'opened' except IOError, e: print 'failed',e.message finally: f.close() print 'closed' if __na