Re: Why no "cause" constructors for NumberFormatException
Twisted wrote:
On Jul 10, 1:10 am, dvdav...@pobox.com wrote:
IllegalArgumentException implements the (relatively) new contructors
that include a Trhowable as a "cause". But NumberFormatException,
which extends IllegalArgumentException, does not. Anybody know why?
I guess they forgot it, or just haven't gotten around to it yet.
Submit it to Sun's bug tracker and they'll probably have it in Java 7.
That could be RFE at best, not a bug report.
Quote from Throwable Javadoc:
"Further, as of release 1.4, many general purpose Throwable classes
(for example Exception, RuntimeException, Error) have been retrofitted
with constructors that take a cause. This was not strictly necessary,
due to the existence of the initCause method, but it is more convenient
and expressive to delegate to a constructor that takes a cause."
More there:
http://java.sun.com/javase/6/docs/api/java/lang/Throwable.html
Just to summarize that, the solution for the OP's problem (already
mentioned also by Lew in this thread) seems to be:
...
} catch (NumberFormatException e) {
throw (NumberFormatException)
new NumberFormatException("new message").initCause(e);
}
piotr