Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > getMethodName()

Reply
Thread Tools

getMethodName()

 
 
google@aikempshall.freeserve.co.uk
Guest
Posts: n/a
 
      01-25-2006
I have the following code in a subroutine of a class which is intended
to give the user (me) some information as to the nature of the error.
In addition I want to include in the MessageDialog the name of the
method that invoked the error. How do I get hold of the method name
when running?
See below especially ??????.getMethodName. Am I close?

try {


} catch (ParserConfigurationException pce) {

JOptionPane.showMessageDialog(
null,
"explicit error message",
??????.getMethodName() + " ParserConfigurationException - Error!",
JOptionPane.ERROR_MESSAGE);

}

 
Reply With Quote
 
 
 
 
Gordon Beaton
Guest
Posts: n/a
 
      01-25-2006
On 25 Jan 2006 06:34:53 -0800, wrote:
> I have the following code in a subroutine of a class which is
> intended to give the user (me) some information as to the nature of
> the error. In addition I want to include in the MessageDialog the
> name of the method that invoked the error.


> How do I get hold of the method name when running?


[...]

> } catch (ParserConfigurationException pce) {
>
> JOptionPane.showMessageDialog(
> null,
> "explicit error message",
> ??????.getMethodName() + " ParserConfigurationException - Error!",



Read the documentation for java.lang.Throwable. This is what you need:

pce.getStackTrace()[0].getMethodName();

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
 
 
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      01-25-2006
wrote:
> I have the following code in a subroutine of a class which is intended
> to give the user (me) some information as to the nature of the error.
> In addition I want to include in the MessageDialog the name of the
> method that invoked the error. How do I get hold of the method name
> when running?


Start with Throwable.getStackTrace(). The rest is apparent from the API
documentation of that method. I am to lazy to look it up at the moment.

/Thomas

--
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/...g/java/gui/faq
http://www.uni-giessen.de/faq/archiv....java.gui.faq/
 
Reply With Quote
 
google@aikempshall.freeserve.co.uk
Guest
Posts: n/a
 
      01-27-2006
Interrogating the getStackTrace only got the failed method in the java
libraries. What I wanted was the failed method in the code that I'd
written. However, the above suggestion did point me in the right
direction. So what I did to get the method was to loop through each of
elements of the stack trace until I found a match on my class. I Then
found
fillInStackTrace that put my Method to the top of the stack so then I
could use the above
pce.getStackTrace()[0].getMethodName();

Thanks

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57