-
How do you programatically get access to the names and contents of all variables in the current vari
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