Re: Some help with error messages

Jeff Allen <[email protected]> Thu, 18 Aug 2016 07:37:33 +0100
Newsgroups gmane.comp.lang.jython.user
Message-ID <[email protected]>
Syntax errors are mostly reported directly from code generated by the 
ANTLR parser-generator, so will reflect its conventions: "no viable 
alternative" is one of those. A move to ANTLR 4 (suggested but not 
straightforward) could change them somewhat, but they are quite 
stylised. Our guidance for other error messages is to be as like the 
ones from CPython as is sensible -- nothing more formal is consistently 
followed.

The code that formats exceptions for output (may help with your ideas) 
is here: 
https://hg.python.org/jython/file/tip/src/org/python/core/Py.java#l1173

It may also be worth looking at sys.excepthook as an alternative to 
catching the exception, but catching sounds like a natural Java approach.

Jeff Allen

On 16/08/2016 20:15, James Ervin wrote:
> I was wondering if someone could point me to either the jython class 
> or a document where the format of error messages is defined.
>
> I am working on embedding a jython engine inside an Eclipse RCP 
> application.  I would really love to be able to extract line numbers 
> (if not exact character offsets) from errors generated by bad python code.
>
> For example I get:
> SyntaxError: ("no viable alternative at input 'crap'", ('<string>', 5, 
> 11, '    crappy crap crap\n'))
>
> I am trying to figure out how to successfully extract the 5 and 11 there.
>
> Another example:
> Traceback (most recent call last):File "<string>", line 1, in 
> <module>AttributeError: 'NoneType' object has no attribute 'getName'
>
> Obviously the line followed by the number should be sufficient.
>
> Also is there a better way to get these errors than catch exceptions 
> from PythonInterpreter.exec()?
>
> Thanks,
> James E. Ervin, IV
>
> "Noli nothis permittere te terere."
> "Romanes eunt domus."
> Blog: http://iacobus.blogspot.com
>
>
> ------------------------------------------------------------------------------
>
>
> _______________________________________________
> Jython-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/jython-users


------------------------------------------------------------------------------