Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

getMethodName()

Thread view: 
google@aikempshall.freeserve.co.uk - 25 Jan 2006 14:34 GMT
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);
           
       }
Gordon Beaton - 25 Jan 2006 14:39 GMT
> 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

Signature

[  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

Thomas Weidenfeller - 25 Jan 2006 14:42 GMT
> 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

Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/

google@aikempshall.freeserve.co.uk - 27 Jan 2006 14:55 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.