From: John H. <jdh...@ac...> - 2004-11-24 15:35:03
|
>>>>> "Steve" == Steve Chaplin <ste...@ya...> writes: Steve> For an IOError the exception attribute 'filename' is set to Steve> the filename. With your example above Steve> self.renderer._renderer.write_png(str (filename)) is Agg Steve> C++ extension code The line fp = fopen(file_name, "wb"); Steve> could be changed to something like if ((fp = Steve> fopen(file_name, "wb")) == NULL) throw Py::IOError("could Steve> not open file", filename); Steve> 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 |