propagation of error messages in matplotlib

For an IOError the exception attribute 'filename' is set to

    > the filename. With your example above
    > self.renderer._renderer.write_png(str (filename)) is Agg
    > C++ extension code The line fp = fopen(file_name, "wb");
    > could be changed to something like if ((fp =
    > fopen(file_name, "wb")) == NULL) throw Py::IOError("could
    > not open file", filename);

    > Does this look right John?

Right in principle, but not in practice.

For one thing, cxx strangely doesn't define an IOError. I don't know
if this is simply an oversight. Perhaps I'll file a bug on the sf
site....

The larger problem is that the exception constructor doesn't accept
multiple args and concatenate them. It would be nice if it did.

I added a Printf class to mplutils to ease the burden of making printf
style strings in C++ to make better exceptions, and updated the
exceptions in the image, agg and ft2font extensions. The standard
usage is

    if ((fp = fopen(file_name, "wb")) == NULL)
      throw Py::RuntimeError( Printf("Could not open file %s", file_name).str() );

JDH

The Python C API uses
PyErr_SetFromErrnoWithFilename(PyObject *type, char *filename)
to raise IOError exceptions, perhaps cxx has an equivalent function.

Steve

···

On Wed, 2004-11-24 at 09:34 -0600, John Hunter wrote:

For one thing, cxx strangely doesn't define an IOError. I don't know
if this is simply an oversight. Perhaps I'll file a bug on the sf
site....