views:

81

answers:

2

I'm using try except block in python, while the try block fails , how to print meaningful error message. I'm looking for something like perror() in C

+1  A: 
>>> try:
...     0/0
... except Exception,e:
...     print e.message
...
integer division or modulo by zero

or in Python 2.6 and above, e.args, because of BaseException.message has been deprecated

>>> try:
...     0/0
... except Exception,e:
...     print e.args
...
('integer division or modulo by zero',)
S.Mark
I'm using python 2.6 ,so e.args works fine.Thanks
lakshmipathi
A: 
try:
   pass
except Exception, err:
   print err
kaizer.se