Add user info to java stack trace

Is there a way to add more information to the Javatrace stack?

I am developing an interpreter for the script language and would like to see the corresponding lines of script code in the java stack.

The result might look something like this:

java.lang.NullPointerException at package.IPF_Try.execute(IPF_Try.java:76) called in script.scr:155 at package.IPF_Block.execute(IPF_Block.java:304) at package.IPF_If.execute(IPF_If.java:105) called in script.scr:130 at package.IPF_Block.execute(IPF_Block.java:304) at package.IPF_Main.execute(IPF_Main.java:147) ... 

or that:

 java.lang.NullPointerException at package.IPF_Try.execute(IPF_Try.java:76) --- called in script.scr:155 --- at package.IPF_Block.execute(IPF_Block.java:304) at package.IPF_If.execute(IPF_If.java:105) --- called in script.scr:130--- at package.IPF_Block.execute(IPF_Block.java:304) at package.IPF_Main.execute(IPF_Main.java:147) ... 

This will simplify debugging, unfortunately, Google could not find anything to achieve this.

The only way I could think of is to dynamically generate a lot of classes using methods whose name contains the information I need and which simply call the next method on the stack, but it seems like a waste of memory (permgen) and loop cycles for me.

+6
source share
1 answer

If you translate your scripts into bytecode, you can provide debugging details using SourceFile and LineNumber .

I am not aware of the mechanism for entering information into the call stack at runtime.

+1
source

Source: https://habr.com/ru/post/896105/


All Articles