This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

toString() throws UndeclaredThrowableException

 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought it might be fun to pose as a question an issue that I just resolved, so you advanced Java people can demonstrate your knowledge!
We are all familiar with the toString() method, which is declared and defined in java.lang.Object.

Notice that it is declared not to throw any checked Exceptions.
In my program, I called toString() on an Object and got an UndeclaredThrowableException. This was a surprise, as all Objects ought to have a toString() and it is not allowed to throw any checked Exceptions.
What was going on?
(As I say, I've resolved this issue, but I thought people might be interested).
[ January 31, 2003: Message edited by: Peter Chase ]
 
Vijayakumar Arya
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I just went through the Java Documentation and found something.
Taken from the Java Documentation:
As of release 1.4, this exception has been retrofitted to conform to the general purpose exception-chaining mechanism. The "undeclared checked exception that was thrown by the invocation handler" that may be provided at construction time and accessed via the getUndeclaredThrowable() method is now known as the cause, and may be accessed via the Throwable.getCause() method, as well as the aforementioned "legacy method."

As it is said here you might be using reflections to invoke the member toString();
-----------------------------
Vijay.
The Hand that gives, Gathers.
[ February 03, 2003: Message edited by: Vijayakumar Arya ]
[ February 03, 2003: Message edited by: Vijayakumar Arya ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic