-
Re: How do you programatically get access to the names and contents of all variables in the current
But if you are running a web application which is running java components
it would be a good thing if it was possible to retrieve variable information
programmtically if you want to do debug stuff, for example
with the Log4j component.
http://jakarta.apache.org/log4j/docs/index.html
Remote debugging of java components which is executed from JSP or Servlets
with JBuilder requires enterprise edition as far as I can see, and
that is very expensive.
If it really is so impossible to get local variable information
at runtime, then how are these debugging environments for example
JBuilder implemented ?
"Paul Clapham" <pclapham@core-mark.com> wrote:
>You want a memory dump! But there's no way of doing that in Java. You
>might want to get yourself one of those IDEs like JBuilder or Visual Cafe
>where you can look at the variables as your class runs.
>
>PC2
>
>"Niklas" <niklas54321@yahoo.se> wrote in message
>news:3b2937b4$1@news.devx.com...
>>
>> How do you programatically get access to the names and contents of all
>variables
>> in the current variable scope ?
>> (attributes and local variables in the current method)
>>
>> I am usually mostly interested in Strings and the primitive datatype
>> int , but any objects toString() representation might also be of interest.
>>
>> What I would like to do, is to *avoid* manually concatenating here and
>there
>> in
>> the code like the ugly code example below, and being able to let
>> java itself figure out what attributes and local variables that currently
>> exist in the
>> method with the code.
>>
>> As an example, I would like to be able to replace hardcoded code like
>this:
>> <pre>
>> try {
>> // ... some code...
>> }
>> catch(myException e) {
>> String s = "An exception occurred in myClass.myMethod, when the
>> attributes and local variables had the following values: ";
>> s += " myStringAttribute = " + myStringAttribute ;
>> s += ", myIntAttribute = " + myIntAttribute;
>> s += ", myLocalString = " + myLocalString;
>> s += ", myLocalInt = " + myLocalInt;
>> writeToLogfile(s);
>> }
>> </pre>
>>
>> with call to some general method which automatically retrieves a string
>with
>> the names
>> and the contents of all attributes and local variables, kind of like this:
>> <pre>
>> try {
>> // ... some code...
>> }
>> catch(myException e) {
>> String s = "An exception occurred in myClass.myMethod, when the attributes
>> and local variables had the following values: ";
>> s += SomeClass.getStringWithAllVariableNamesAndValues(); // Here the
>requested
>> method is called
>> writeToLogfile(s);
>> }
>> </pre>
>>
>> Does it exist such a class and method in the standard java distribution,
>> or as a third party class ?
>>
>
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks