jQuery in Action, 3rd edition
The moose likes Java in General and the fly likes toString() throws UndeclaredThrowableException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "toString() throws UndeclaredThrowableException" Watch "toString() throws UndeclaredThrowableException" New topic

toString() throws UndeclaredThrowableException

Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
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 ]

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Vijayakumar Arya
Ranch Hand

Joined: Jan 27, 2003
Posts: 76
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();
The Hand that gives, Gathers.
[ February 03, 2003: Message edited by: Vijayakumar Arya ]
[ February 03, 2003: Message edited by: Vijayakumar Arya ]

Thanks,<p>Vijay<p>The Hand that gives, Gathers.
I agree. Here's the link: http://aspose.com/file-tools
subject: toString() throws UndeclaredThrowableException
It's not a secret anymore!