access to variables within stack trace

B

breyguhn

Can anyone think of a reason why you can't access the values of
variables / function parameters from within an exception's stack trace
info? Surely the runtime environment that throws the exception has
access to them...

Just not implemented, or is there something more fundamental at work
here?

If so, what tools like jdb do to get access to the values?

Or am I being daft? ;-)

--brey
 
S

SPG

Depends how you wan tto access them
Some IDEs like JBuilder maintain the stack during debugging and you are able
to walk the stack and check variable values at that point.

Steve
 
B

breyguhn

I meant programmatically.

Would be nice to be able to get the value of parameter X that was
passed to method Y, at position Z in your stack. Then you can either
log more information about what blew up where, or to use them to
cunningly process an exception with a lot more precision.

I don't necessarily mean throwing my own exceptions and passing
information therein; I mean also things like NullPointerExceptions and
suchlike.

--brey
 
P

P.Hill

breyguhn said:
I meant programmatically.

Would be nice to be able to get the value of parameter X that was
passed to method Y, at position Z in your stack. Then you can either
log more information about what blew up where, or to use them to
cunningly process an exception with a lot more precision.

no don't do that OR part: 'cunninly process an exception'
What you are saying is that you will behave differently
depending on who called you, but only during exception
processing.

If you just want more stack trace information you can get
the stack trace and talk about it, i.e. manipulate the strings found
within,if you REALLY want to you can even look for certain names in
the stack trace.

Sounds not "daft" but "graft" to me, because now intead of just
design by contract, we have a contract, but it doesn't depend on meeting
the contractual obligation of the interface, but also requires the
caller to be the right object or class. Maybe "descrimination" is
better analogous word; 'class descrimination', call the socialists
workers party they need to know about this!
I don't necessarily mean throwing my own exceptions and passing
information therein; I mean also things like NullPointerExceptions and
suchlike.

And why would who the caller is effect how you would respond to NPE?

Maybe you can describe a real example where this makes sense,
because obviously it sounds like bad object behavior to me.

Suspicious but curious,
-Paul
 
B

breyguhn

ok, forget the exception handling - I take your point, not really
clean object behaviour. I was just trying to think of somewhere else
it might impact...

think just for debugging: this is the only reason you really care
about an exception's stacktrace, no?

specifically for when you can't easily plug a jdb-like tool in, such
as jsp/servlet coding; you can see the stacktrace, but without often
prodigious logging of variable values it's hard to see specifically
why something broke. If the exception methods gave you access to the
variables as well as the file name, line number etc. it's be easier to
figure out exactly what caused your often cryptically described NPE.

--brey
 

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,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top