+ Reply to Thread
Results 1 to 2 of 2

Thread: Handling Exceptions in Rhino's Editor

  1. #1

    Handling Exceptions in Rhino's Editor

    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:

    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
    A standard CPython interpreter would create a Traceback that looks like 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.'
    Running the same code in Rhino's environment produces this:

    Code:
    Message: SubError
    
    Traceback:
      line 13, in <module>, "C:\Users\frankfralick\AppData\Local\Temp\TempScript.py"
    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?

  2. #2
    Senior Member Steve Baer's Avatar
    Join Date
    Apr 2010
    Location
    Seattle
    Posts
    1,464
    Blog Entries
    19
    This looks like something I probably need to fix in the embedded python interpreter. I don't have a good answer for what to do for the time being.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts