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 / May 2006

Tip: Looking for answers? Try searching our database.

dump the program in exception

Thread view: 
cmk128@hotmail.com - 11 May 2006 07:43 GMT
Hi All
       try {
       } catch (Exception ex) {
           // Hi all, how to dump the call stack? and how to auto
detect which local variable in this function have and print their type,
name and value out?
       }

thanks
from Peter (cmk128@hotmail.com)
Stefan Schulz - 11 May 2006 08:27 GMT
The stack trace can be dumped rather trivally using the
printStackTrace() method of Exception... i am a bit stumped about the
second part of your question, though. What do you expect to do? Print
all the local variables in scope to the catch block? Or somehow try to
access the local variables in the stack frame that caused the
exception. The former should be easy enough - the later is impossible
AFAIK, since the stack frame is already destroyed when the catch block
begins to execute.
cmk128@hotmail.com - 11 May 2006 08:47 GMT
thank you very much for your reply first
  In Jbuilder, when i press the program, jbuilder can auto detect
which variable in your current scope and print the value of them. I
want to do the same thing.

thanks
from Peter
halfdog - 11 May 2006 09:51 GMT
I have posted a similar problem, but I also wanted to get all
variables, from all threads. As it seems there is no solution from
within java, only the debugger can examine the stack. No automated
solutions seem to be available. See comp.lang.java.programmer: "Dump
complete java VM state as core dump (not via OS) possible?"
http://groups.google.at/group/comp.lang.java.programmer/browse_frm/thread/a61370
569e550bbe/5bdd61b05f8e3c09?lnk=arm#5bdd61b05f8e3c09

Chris Uppal - 11 May 2006 10:58 GMT
>    In Jbuilder, when i press the program, jbuilder can auto detect
> which variable in your current scope and print the value of them. I
> want to do the same thing.

You can't unless you are willing to use the JVMTI interfaces that the debugger
uses.  Note that those interfaces are for /other/ processes (e.g. a debugger)
to use, and cannot (reliably) be used by a program on itself.

I.e. it's not really possible.

   -- chris
halfdog - 11 May 2006 16:02 GMT
Good tip, but it is really bad that you are right with your post: I
looked at the JPDA interfaces and its not quite easy. The packets to
retrieve stack-traces are moderately complex, but as I see it, there is
no other means to retrieve a list of all instanciated objects, then to
start from all threads and loop over all references to collect
everything that is reachable.

I've also sent a request to the java-soft product help desk asking
these questions, lets see what they say about it.
Stefan Schulz - 11 May 2006 12:05 GMT
This seems to be some kind of interface to the debugger JBuilder
(presumably) bundles. This is not possible (AFAIK) if running outside
of a debugger.


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.