How to know the name of the (parent) method that invoked another method

Hi,

I am working to build my own Exception.

If I have a method B that produces an exception, can I know the name of the method A that invoked method B, in order to trace it?

This is specially useful in utility classes that uses JDBC to get data.

Thanks very much,

Regards,

Lorenzo Jimenez

[331 byte] By [Lorenzo_Jimeneza] at [2007-11-26 16:25:44]
# 1
Just create a java.lang.Exception and it'll be in the stack trace info.
YAT_Archivista at 2007-7-8 22:49:47 > top of Java-index,Core,Core APIs...
# 2
> Just create a java.lang.Exception and it'll be in the> stack trace info.no need for all that expenseThread.currentThread().getStackTrace();read Teh Docs ™ for StackTraceElement, to find out how to use the stack trace
georgemca at 2007-7-8 22:49:47 > top of Java-index,Core,Core APIs...
# 3
Thanks it worked very well!Lorenzo
Lorenzo_Jimeneza at 2007-7-8 22:49:47 > top of Java-index,Core,Core APIs...
# 4
> no need for all that expenseWhat expense? Since he's already creating an exception, it's free.
YAT_Archivista at 2007-7-8 22:49:47 > top of Java-index,Core,Core APIs...
# 5
> > no need for all that expense> > What expense? Since he's already creating an> exception, it's free.fair point!
georgemca at 2007-7-8 22:49:47 > top of Java-index,Core,Core APIs...
# 6

> I am working to build my own Exception.

>

> If I have a method B that produces an exception, can

> I know the name of the method A that invoked method

> B, in order to trace it?

>

You know that you don't have to add the stack trace to an exception yourself - right?

jschella at 2007-7-8 22:49:47 > top of Java-index,Core,Core APIs...
# 7

> > I am working to build my own Exception.

> >

> > If I have a method B that produces an exception,

> can

> > I know the name of the method A that invoked

> method

> > B, in order to trace it?

> >

>

>

> You know that you don't have to add the stack trace

> to an exception yourself - right?

another fair point! this is what comes of answering the subject line rather than the post.....

on the ball as usual, Joe

georgemca at 2007-7-8 22:49:47 > top of Java-index,Core,Core APIs...