From: John H. <jdh...@ac...> - 2005-02-14 21:54:52
|
>>>>> "Ted" == Ted Drain <ted...@jp...> writes: Ted> OK - I think I've read most of those messages and had a few Ted> comments/ideas. Soapbox mode on: Please don't change the Ted> system exception hook. Matplotlib (MPL) is not an Ted> application, it's a library. Libraries should never change Ted> global behavior - only applications. By changing global Ted> behavior you severely limit how and where your library can be Ted> used by others. Soapbox mode off. Point taken. One might view the pylab interface as an application, but I won't quibble. Ted> I wonder if it helps to think about errors from a different Ted> stand point. For example, I can think of two high level Ted> views that might help. Users interact with MPL either Ted> through the Python command line (via typing or scripts) or Ted> through GUI front ends. Ted> 1) A python function is called which has an error (or Ted> something it calls has an error, etc, etc). In this case, if Ted> the function throws an exception, python will propagate the Ted> exception normally. If you're typing something on the prompt Ted> or running a script, the exception get's printed with a trace Ted> back. Very useful and very normal for Python. There is a wrinkle here. On win32 (or another platform that binds python scripts to an executable), you might double click on a script from pylab import * semilogy([0,1,2,3]) show() In pre 0.72 mpl, this would throw an exception. On windows, if you double clicked this script, a stdout window would launch and die before you could read the traceback -- very annoying. That's the primary reason I tried to catch exceptions in the pylab interface and forward them on to the error_msg handler function. But the current impl. is admittedly broken. Do you have a suggestion for how to handle this case? We could do something like this: all GUIs define a function show_message. This pops up a message dialog with a single OK button. pylab dies the following def plot(*args, **kwargs): # allow callers to override the hold state by passing hold=True|False b = ishold() h = popd(kwargs, 'hold', None) if h is not None: hold(h) try: ret = gca().plot(*args, **kwargs) except: msg = ...get the traceback as string ... show_message(msg) hold(b) ...rethrow the same exception.... else: try: draw_if_interactive() except: msg = ...get the traceback as string... show_message(msg) hold(b) ...rethrow the same exception.... hold(b) return ret Someone please remind me how to rethrow the last exception -- Fernando? Or we could just ignore it and let win32 users who are double clicking scripts die the painful death they deserve. It would certainly make for cleaner pylab code. Ted> - Error trying to save the plot to the image file 'plot.png'. Ted> - Error in the automatic plot layout algorithm. - Error in Ted> setting the size of the plot region. The inputs size of Ted> [-10, 200] is invalid. This gives you more diagnostic information in that you get helpful messages at each level, but the standard traceback gives you all the levels, no? JDH |