Extract traceback using AST

Hi,

Let say, we have a try-catch statement
try
{

}
catch (Exception e)
{
Response.Write(e.ToString());
}

How can I extract the traceback from the Exception (assuming it’s of unknown origin ) once I get the AST?

Thanks

If I understand your question correctly, you’re looking for the stack trace itself, is that right?

If so, then that isn’t something you can get from the AST itself: The UAST is constructed from the source text alone, while stack traces are generated when the program runs. Babelfish only parses the program, but does not run it, so we have no way to obtain a stack trace.

On the other hand, if you already have a stack trace from some other source, you may be able to use the line information from the stack trace to locate the positions of the nodes in a UAST corresponding to the classes or methods it mentions. Babelfish doesn’t do that correlation automatically, but the Position information in each Node should be sufficient to let you write that.

3 Likes

Hi Michael,

Thank you for the reply.

[…] you’re looking for the stack trace itself, is that right?

Yes, that’s the idea (in one presentation of Babelfish, Reference resolution was mentioned).

The second part of your answer is helpful.
As I can get a stack trace from some other source, I’ll try to implement the correlation.

Thanks