Your code would obviate the need for a separate "except java.lang.Throwable" clause. How about this code instead of " try and except AttributeError".

*********
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 exception handling code?

Raghu.

On 9/8/05, Jeff Emanuel <jemanuel@frii.com> wrote:
Sorry cut-n-paste error, the first part should have been:

>>> try:
...   a=b
... 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


Jeff Emanuel wrote:
>  >>> try:
> ...   a=b
> ... 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@comcast.net> 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@comcast.net <mailto:hzwi@comcast.net>
>>>>
>>>>> wrote:
>>>>
>>>>
>>>> The following should do the job:
>>>>
>>>> from java.lang import Throwable
>>>> import traceback
>>>> import testje
>>>> try:
>>>> t = 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 Practices
> Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
> Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
> _______________________________________________
> Jython-users mailing list
> Jython-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jython-users