Your code would obviate the need for a separate "except java.lang.Throwable=
"=20
clause. How about this code instead of " try and except AttributeError".=20
*********
if (isinstance(sys.exc_info()[1], java.lang.Throwable)):
sys.exc_info()[1].printStackTrace()
*********
Would this be preferable in any way to using try/except clause inside=20
exception handling code?=20
Raghu.
On 9/8/05, Jeff Emanuel <jemanuel@...> wrote:
>=20
> Sorry cut-n-paste error, the first part should have been:
>=20
> >>> try:
> ... a=3Db
> ... except:
> ... traceback.print_exc() # python part
> ... try:
> ... sys.exec_info()[1].printStackTrace() # java part
> ... except AttributeError:
> ... pass # no java part
> ...
> Traceback (most recent call last):
> File "<console>", line 2, in ?
> NameError: b
>=20
>=20
> Jeff Emanuel wrote:
> > >>> try:
> > ... a=3Db
> > ... except:
> > ... traceback.print_exc() # python part
> > ... try:
> > ... sys.exec_info()[1].printStackTrace() # java part
> > ... except AttributeError:
> > ... pass # no java part
> > ...
> > Traceback (most recent call last):
> > File "<console>", line 2, in ?
> > java.lang.NullPointerException: java.lang.NullPointerException
> > >>> try:
> > ... java.lang.String(None)
> > ... except:
> > ... traceback.print_exc()
> > ... try:
> > ... sys.exc_info()[1].printStackTrace() # java part
> > ... except AttributeError:
> > ... pass # no java part
> > ...
> > Traceback (most recent call last):
> > File "<console>", line 2, in ?
> > java.lang.NullPointerException: java.lang.NullPointerException
> > java.lang.NullPointerException
> > at java.lang.String.<init>(String.java:144)
> > at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
> > Method)
> >
> > at
> > sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct
> > orAccessorImpl.java:39)
> > at
> > sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC
> > onstructorAccessorImpl.java:27)
> > at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
> > at
> > org.python.core.PyReflectedConstructor.__call__(PyReflectedConstructo
> > r.java)
> > at org.python.core.PyJavaInstance.__init__(PyJavaInstance.java)
> > at org.python.core.PyJavaClass.__call__(PyJavaClass.java)
> > at org.python.core.PyObject.__call__(PyObject.java)
> > at org.python.core.PyObject.invoke(PyObject.java)
> > at org.python.pycode._pyx25.f$0(<console>:2)
> > at org.python.pycode._pyx25.call_function(<console>)
> > at org.python.core.PyTableCode.call(PyTableCode.java)
> > at org.python.core.PyCode.call(PyCode.java)
> > at org.python.core.Py.runCode(Py.java)
> > at org.python.core.Py.exec(Py.java)
> > at org.python.util.PythonInterpreter.exec(PythonInterpreter.java)
> > at
> > org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter
> > .java)
> > at
> > org.python.util.InteractiveInterpreter.runsource(InteractiveInterpret
> > er.java)
> > at
> > org.python.util.InteractiveInterpreter.runsource(InteractiveInterpret
> > er.java)
> > at org.python.util.InteractiveConsole.push(InteractiveConsole.java)
> > at
> > org.python.util.InteractiveConsole.interact(InteractiveConsole.java)
> > at org.python.util.jython.main(jython.java)
> >
> >
> > Raghuram Devarakonda wrote:
> >
> >> That explains. Unfortunately, it requires that "except
> >> java.lang.Throwable" clause is required in addition to generic
> >> "except" clause even when I have same code in case of all exceptions
> >> (python and java).
> >>
> >> Raghu.
> >>
> >> ps. I just noticed that Helio R. Zwi didn't reply to the group.
> >> On 9/8/05, Helio R. Zwi <hzwi@...> wrote:
> >>
> >>> Raghuram Devarakonda wrote:
> >>>
> >>>
> >>>> Yes, it does work. Thanks a lot for the quick response. Is there any
> >>>> reason that traceback.print_exc() doesn't print complete stack trace=
?
> >>>>
> >>>> Raghu.
> >>>>
> >>>> On 9/8/05, *Helio R. Zwi* <hzwi@... <mailto:hzwi@...=
>
> >>>>
> >>>>> wrote:
> >>>>
> >>>>
> >>>> The following should do the job:
> >>>>
> >>>> from java.lang import Throwable
> >>>> import traceback
> >>>> import testje
> >>>> try:
> >>>> t =3D testje()
> >>>> t.te()
> >>>> except Throwable, e:
> >>>> e.printStackTrace()
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>> print_exc (and other methods in traceback) work with the /python/
> >>>>> stack
> >>>>> trace. The /Java/ stack trace is a property (actually, a private
> >>>>> member) of the java.lang.Throwable instance.
> >>>
> >>>
> >>>
> >>>
> >>
> >
> >
> > -------------------------------------------------------
> > SF.Net email is Sponsored by the Better Software Conference & EXPO
> > September 19-22, 2005 * San Francisco, CA * Development Lifecycle=20
> Practices
> > Agile & Plan-Driven Development * Managing Projects & Teams * Testing &=
=20
> QA
> > Security * Process Improvement & Measurement *=20
> http://www.sqe.com/bsce5sf
> > _______________________________________________
> > Jython-users mailing list
> > Jython-users@...
> > https://lists.sourceforge.net/lists/listinfo/jython-users
>
|