This may be a broader IronPython question. I need to code a variety of custom exceptions that have helpful messages. In the past with CPython I have made a class hierarchy of exceptions, so that I can test many conditions it a try statement, and then catch any of them using the superclass exception. Like this:
A standard CPython interpreter would create a Traceback that looks like this:Code:class SuperError(Exception): pass class SubError(SuperError): def __init__(self,x): self.x = x def __str__(self): return repr(str(self.x)+" is not less than three.") x = 4 try: if x > 3: raise SubError(x) except SuperError as Y: raise Y
Running the same code in Rhino's environment produces this:Code:Traceback (most recent call last): File "C:\Projects\Interop\exceptions.py", line 13, in <module> raise Y SubError: '4 is not less than three.'
Not as useful. Does this have to do with how IronPython is being embedded (ScriptSource.Execute vs. ExecuteProgram or something like that)? If I insert a like "print Y" above "raise Y" it will print the exception message to the command prompt window it Rhino's UI, which will work for now but is not a good solution. Is there a way around this?Code:Message: SubError Traceback: line 13, in <module>, "C:\Users\frankfralick\AppData\Local\Temp\TempScript.py"


Reply With Quote