SourceForge logo
SourceForge logo
Menu

Re: [matplotlib-devel] propagation of error messages in matplotlib

From: Steve C. <ste...@ya...> - 2004年11月24日 13:23:22
On Wed, 2004年11月24日 at 12:06 +0000, Jochen Voss wrote:
> Hello,
> 
> On Fri, Nov 19, 2004 at 10:33:43AM -0600, John Hunter wrote:
> > >>>>> "Jochen" == Jochen Voss <vo...@se...> writes:
> > Jochen> Slight problem: it might now be a little bit more
> > Jochen> difficult to include the name of the file which could not
> > Jochen> be opened in the error message. The IOError exception
> > Jochen> will probably only have "permission denied" associated
> > Jochen> with it.
> > 
> > Looks OK, at least on linux
> > 
> > 
> > >>> file('/sbin/ldconfig', 'w')
> > Traceback (most recent call last):
> > File "<stdin>", line 1, in ?
> > IOError: [Errno 13] Permission denied: '/sbin/ldconfig'
> 
> But sometimes it doesn't give the file name:
> 
> >>> from matplotlib.matlab import *
> >>> plot([1,2,3],[2,3,1])
> [<matplotlib.lines.Line2D instance at 0x41ef774c>]
> >>> savefig("/forbidden.png")
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File ".../matlab.py", line 1009, in savefig
> manager.canvas.print_figure(*args, **kwargs)
> File ".../backends/backend_gtkagg.py", line 69, in print_figure
> agg.print_figure(filename, dpi, facecolor, edgecolor, orientation)
> File ".../backends/backend_agg.py", line 379, in print_figure
> self.renderer._renderer.write_png(str(filename))
> RuntimeError: could not open file
> 
> I did not investigate what happens here, but if there is an easy way to
> get the file name into the exception we should probably use it.
> 
> All the best,
> Jochen
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?
Steve

View entire thread

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /