dump the program in exception

C

cmk128

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 ([email protected])
 
S

Stefan Schulz

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.
 
C

cmk128

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
 
C

Chris Uppal

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
 
S

Stefan Schulz

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.
 
H

halfdog

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top