The use of sys.exc_info for catching exceptions

Tiago M. Vieira tmv at redhat.com
Wed Feb 1 04:59:01 EST 2017


Hi,

I've came to a problem where I want to keep backwards and forwards
compatibility with an exception syntax. And I mean by backwards going
further down to Python 2.5.

I was pointed to this option from a stack overflow answer[1] that works
forward and backwards, I rewrite the solution here:

import sys
try:
    pr.update()
except (ConfigurationException,):
    e = sys.exc_info()[1]
    returnString = "%s %s" % (e.line, e.errormsg)


I understand that there has been a discussion about deprecating
sys.exc_info() on [1] and in section "Possible Future Compatible Changes"
on [2].

Aside of deprecating this function, what could be other possible issues if
I use the solution above? Performance overhead or any known case that
could cause problems?

[1] - http://stackoverflow.com/a/2513890¬
[2] - https://www.python.org/dev/peps/pep-3110/#open-issues
[3] - https://www.python.org/dev/peps/pep-3134/

Thanks!

-- 
    Tiago
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 880 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20170201/a375d3e8/attachment.sig>


More information about the Python-list mailing list