My mistake! Did something change between 2.6.1 and 2.6.4, or did Maya just handle the implementation differently?
On Fri, Mar 25, 2011 at 2:07 PM, Ofer Koren <[email protected]> wrote: > You've overriden the base class Exception __init__ method and haven't > replaced it's behaviour properly. The Exception classes store the message > string in a .msg attribute (or .message, i don't remember exactly). You also > didn't implement the __repr__ method, which most likely relies on that > attribute. Try this: > > > class SelectionError(Exception): > def __init__(self, value): > Exception.__init__(self, value) > > raise SelectionError('You selected too many objects') > > > - Ofer > www.mrbroken.com > > > On Fri, Mar 25, 2011 at 10:42 AM, Adam Mechtley > <[email protected]>wrote: > >> Thanks, Jesse! Not to beat a dead horse here, but for the sake of >> posterity: >> >> Without stack trace enabled, Maya 2011+ won't print a custom exception >> message for a derived class, but *WILL* print it if you just call the >> base class. For example: >> >> class SelectionError(Exception): >> >> def __init__(self, value): >> >> self.value = value >> >> def __str__(self): >> >> return self.value >> >> try: raise SelectionError('You selected too many objects') >> >> except: raise >> >> >> will print >> >> >> # Error: SelectionError: file <maya console> line 1: # >> >> >> However, just doing this >> >> >> try: raise Exception('You selected too many objects') >> >> except: raise >> >> >> will print this >> >> # Error: Exception: file <maya console> line 1: You selected too many >> objects # >> >> >> On Thu, Mar 24, 2011 at 7:55 PM, Jesse Kretschmer <[email protected]>wrote: >> >>> >>>> IDLE will print: >>>> >>>> >>>> Traceback (most recent call last): File "<pyshell#5>", line 2, in >>>> <module> raise SelectionError('You selected too many objects') >>>> SelectionError: You selected too many objects >>>> >>>> >>>> But Maya will print: >>>> >>>> >>>> # Error: SelectionError: file <maya console> line 2: # >>>> >>>> >>>> *Am I missing something really basic here, or can Maya seriously not >>>> print custom exception messages to the console?* >>>> >>> >>> >>> Are you running Maya 2011? If so make sure that *Show Stack Trace* is >>> enabled in the *Script Editor*. It is under the *History *menu. >>> >>> Also you could try printing the error the maya way: >>> import maya.OpenMaya >>> OpenMaya.MGlobal.displayError("String") >>> >>> good luck. >>> >> >> -- >> http://groups.google.com/group/python_inside_maya >> > > -- http://groups.google.com/group/python_inside_maya
