Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • 67
    The problem with this is, for example, if you except Exception as e, and e is an IOError, you get e.errno, e.filename, and e.strerror, but apparently no e.message (at least in Python 2.7.12). If you want to capture the error message, use str(e), as in the other answers. Commented Apr 19, 2017 at 18:28
  • @epalm What if you catch the IOError before Exception? Commented Jan 12, 2020 at 14:21
  • 2
    @HeribertoJuárez Why catch special cases while you can simply cast it to string? Commented Apr 19, 2020 at 18:13