From: John M. <joh...@ya...> - 2001-02-23 21:43:08
|
Just add the following at the top of yout Jython script to fix the problem! from java.lang import Exception --- John Mudd <joh...@ya...> wrote: > I'm trying to use an exception (written in java) in my jython code. > But I seem to get an error. Any suggestions? > > > > $ cat MyException.java > class MyException extends Exception { > int Code; > String Description; > > public MyException(int Code, String Description) { > //super(); > > this.Code = Code; > this.Description = Description; > } > > public String toString() { > return "MyException: Code=" + Code + ", Description=" + > Description; > } > } > > > $ javac MyException.java > > > $ cat testException.py > #! /usr/bin/env jython > > import MyException > > try: > #raise MyException(-1, 'xxxxxxxxx') > de = MyException(-1, 'xxxxxxxxx') > print 'de=%s' % `de` > raise de > except Exception, e: > print 'e=%s' % `e` > > > $ testException.py > de=MyException: Code=-1, Description=xxxxxxxxx > Traceback (innermost last): > File "testException.py", line 9, in ? > MyException: Code=-1, Description=xxxxxxxxx > at java.lang.reflect.Constructor.newInstance(Native Method) > at > org.python.core.PyReflectedConstructor.__call__(PyReflectedConstructor.java:125) > at > org.python.core.PyJavaInstance.__init__(PyJavaInstance.java:61) > at org.python.core.PyJavaClass.__call__(PyJavaClass.java:786) > at org.python.core.PyObject.__call__(PyObject.java:285) > at org.python.pycode._pyx0.f$0(testException.py) > at org.python.pycode._pyx0.call_function(testException.py) > at org.python.core.PyTableCode.call(PyTableCode.java:155) > at org.python.core.Py.runCode(Py.java:1055) > at org.python.core.__builtin__.execfile(__builtin__.java:288) > at org.python.core.__builtin__.execfile(__builtin__.java:292) > at > org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:155) > at org.python.util.jython.main(jython.java:159) > > MyException: MyException: Code=-1, Description=xxxxxxxxx > $ > > > __________________________________________________ > Do You Yahoo!? > Yahoo! Auctions - Buy the things you want at great prices! > http://auctions.yahoo.com/ > > _______________________________________________ > Jython-users mailing list > Jyt...@li... > http://lists.sourceforge.net/lists/listinfo/jython-users __________________________________________________ Do You Yahoo!? Yahoo! Auctions - Buy the things you want at great prices! http://auctions.yahoo.com/ |