Python try except exception showing the message error


When we don’t know about what the kind of error that throwed by try: … except: .., we can just print out the message by:

1
except Exception, e:

And get the error from “message” attribute of “e”. For instance:

1
2
3
4
5
6
a = []

try:
    a[100]
except Exception, e:
    print e.message

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.