[Numpy-discussion] numpy error handling

Rob Hooft rob at hooft.net
Sat Apr 1 22:38:04 CST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Travis Oliphant wrote:
| save = numpy.seterr(dividebyzero='warn')
|
| ...
|
| numpy.seterr(restore=save)

Most of this discussion is outside of my scope, but I have programmed
this kind of pattern in a different way before:

~   save = context.push(something)
~   ...
~   del save

i.e. the destructor of the saved context object restores the old
situation. In most cases it will be called by letting "save" go out of
scope. I know that relying on timely object destruction can be
troublesome when porting to Jython, but it is very convenient in CPython.

If that goes too far, one could make a separate method on save:

~    save.pop()

This can do sanity checking too (are we really at the top of the stack?
Only called once?). The destructor should check whether pop has been called.

Rob

- --
Rob W.W. Hooft  ||  rob at hooft.net  ||  http://www.hooft.net/people/rob/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFEL3EUH7J/Cv8rb3QRAuvsAJ9PO6ZITdVSm+hIwxkWDHHbTNFHdQCcDSWI
Iv7gupkFc8+Fby/5MFwHQf4=
=zE/o
-----END PGP SIGNATURE-----




More information about the Numpy-discussion mailing list