On 02/10/10 06:26 PM, Danek Duvall wrote:
Shawn Walker wrote:

Maybe the compromise is to have an except handler for the call to
exec_fail_actuators that does a "raise e",  but otherwise just calls
raise.  That would at least preserve the traceback origin for the
cases where exec_fail_actuators itself doesn't fail.

Could you try/except: pass on exec_fail_actuators, and then just do a plain
raise?

Nope:

--------------------8=--------------------------

#!/usr/bin/python2.6

def func():
        raise RuntimeError("func error")

try:
        raise RuntimeError("block error")
except:
        try:
                func()
        except:
                pass
        raise

$ ./test.py
...
RuntimeError: func error

--------------------=8--------------------------

Whereas:

--------------------8=--------------------------
#!/usr/bin/python2.6

def func():
        raise RuntimeError("func error")

try:
        raise RuntimeError("block error")
except BaseException, e:
        try:
                func()
        except:
                raise e
        raise
--------------------=8--------------------------

$ ./test.py
Traceback (most recent call last):
  File "./test.py", line 12, in <module>
    raise e
RuntimeError: block error

...at least gives the original error although not from the original location.

But, I stumbled on a bit in the documentation I missed about an alternative syntax that will cause python to re-raise the exception as coming from the original location:

--------------------8=--------------------------
#!/usr/bin/python2.6

import sys

def func():
        raise RuntimeError("func error")

try:
        raise RuntimeError("block error")
except BaseException:
        ext, exv, extb = sys.exc_info()
        try:
                func()
        except:
                pass
        raise exv, None, extb

--------------------=8--------------------------

Traceback (most recent call last):
  File "./test.py", line 9, in <module>
    raise RuntimeError("block error")
RuntimeError: block error

Given this little discovery, perhaps we should change our error handling to take advantage of this in the future?

Cheers,
--
Shawn Walker
_______________________________________________
pkg-discuss mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/pkg-discuss

Reply via email to