Open aneveux opened 13 years ago
Following comments are imported from our previous issue tracker:
I'm a little bit confused with the callstack because, in your example, the method that will throw the exception is part of the callstack. So it will be present in the stack trace of the exception. What kind of additional information do you need in your callstack?
I do not request any additional information. I like to have the Callstack (executable.MyProgram main -> executable.MyExecutable main) available via a Java Object. By that //J users can switch of the //J output as seen in the example above and replace it by their own output or they can evaluate it in their code for other needs.
I propose to add the interface
interface Call {
String getName(); // return the name of the corresponding procedure
Process<?> getProcess(); // return the process that launched the procedure call
}
And an helper class to get an instance of Call.
For instance, in a Runnable:
public class MyRunnable implements Runnable {
public void run() {
Call call = MyHelperClass.getCall(this);
System.out.println("procedure: " + call.getName());
// ...
}
}
What do you think?
I think the Call interface is a great idea, which brings us a big step forward. To complete what I have asked for, we could use this Call interface to get a complete Call StackTrace. So imagine we have:
public class MyRunnable implements Runnable {
public void run() {
Call[] stackTraces = Procedure.getStackTrace();
System.out.println("Current Procedure(A): " + stackTrace[0].getName());
System.out.println("Procedure(B) that called A : " + stackTrace[1].getName());
System.out.println("Procedure(C) that called B : " + stackTrace[2].getName());
//and so on...
}
}
As you have recognized this concept corresponds a little to java.lang.Thread.getStackTrace().
There is no call stack in //J. If you have a -> b -> c. it correspond to:
process() { a(); b(); c(); }
but not to:
process() { a(); } a() { b(); } b() { c(); }
Also, you can know where you are in the process but you cannot know why you are at this stage of the process. The calls executed before are not kept in memory. In my example, in c(), you cannot know that a() and b() were executed before. It would be a big effort to implement that (and a memory leak issue for batch processes).
Although //J logs the visited Programs and Procedures like
it might be helpful, also to provide a Callstack as an object (e.g. Logs.getCallstack()) to allow //J users to use it in their programs (e.g. to pass it as a parameter to an Exception). That allows programmers who use //J to write their own flow logging as they like.