#67 Exceptions unweildy when bsh embedded

open
nobody
General (151)
5
2002-06-10
2002-06-10
Nathan Sharp
No

We are embedding bsh into an application to provide a
scripting capability to our software. I'm currently
trying to fix up the error handling capabilities.
Right now bsh seems to always add the entire contents
of the script to the exception message, making the
Exception almost completely unreadable. I've caught
the EvalError and been able to chop it into a more
readable version using .getErrorLineNumber() and
getErrorText(), except that there seems to be no way to
get at the actual error message without also getting
the entire contents of the string passed to
Interpreter.eval() because something somewhere has
called prependMessage() with the contents of the
evaluation. Is there a clean way to handle this?

Discussion

  • Nathan Sharp
    Nathan Sharp
    2002-06-10

    Logged In: YES
    user_id=297083

    In bsh.Interpreter.eval(String, NameSpace) I changed the
    code to correct for this problem:

    public Object eval( String statement, NameSpace nameSpace )
    throws EvalError {

    String s = ( statement.endsWith(";") ? statement :
    statement+";" );
    return eval(
    // new StringReader(s), nameSpace, "<Inline eval of:
    "+s+" >" );
    new StringReader(s), nameSpace, "<Inline eval>" );
    }

    Note that this does clobber the nice functionality of
    showing the string being evalled for small strings. Our
    strings are just too large for this to be realistic.

    However, the line with the error is still shows up correctly
    in getErrorText() of the EvalError.