Home
Reading
Searching
Subscribe
Sponsors
Statistics
Posting
Contact
Spam
Lists
Links
About
Hosting
Filtering
Features Download
Marketing
Archives
FAQ
Blog
 
Gmane
From: Raghuram Devarakonda <draghuram <at> gmail.com>
Subject: Getting stack trace that includes the Java part
Newsgroups: gmane.comp.lang.jython.user
Date: Monday 13th July 2009 19:49:37 UTC (over 8 years ago)
Hi,

Please take a look at the following test java code:

-----
public class testclass {
    public static String f() {
        return null;
    }

    public static void g() {
        System.out.println(f().length());
    }

    public static void test() {
        g();
    }
}
-----

The code basically sets up a NullPointerException. When called from
the following jython code:

-----
import testclass
testclass.test()
-----

I see the following nice traceback printed on the console:

-----
Traceback (most recent call last):
  File "test1.py", line 3, in 
    testclass.test()
        at testclass.g(testclass.java:8)
        at testclass.test(testclass.java:12)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)

java.lang.NullPointerException: java.lang.NullPointerException
-----

How ever, if I explicitly print the stack trace using
traceback.print_exc() as follows:

-----
import traceback
import testclass

try:
    testclass.test()
except:
    traceback.print_exc()
-----

I only get the following stack trace:

-----
Traceback (most recent call last):
  File "test2.py", line 6, in 
    testclass.test()
NullPointerException: java.lang.NullPointerException
-----

As can be seen, the interpreter seems to be doing something extra in
order to include java's stack trace. Is there a simple way to get this
type of stack trace programmatically from traceback.format_exc() (or
some such API)?

Thanks,
Raghu

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize
 
details at: http://p.sf.net/sfu/Challenge
 
CD: 4ms