[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Chained exceptions
From: |
Mark Wielaard |
Subject: |
Re: Chained exceptions |
Date: |
Tue, 17 Jul 2001 01:15:30 +0200 |
User-agent: |
Mutt/1.3.18i |
Hi,
On Fri, Jul 13, 2001 at 12:44:29PM +0100, Eric Blake wrote:
> A comment about the documentation of chained exceptions:
> [...]
> Notice that to get this to compile, you really need the example to read:
>
> <pre>
> try {
> ...
> } catch (SQLException sqle) {
> throw (IOException) new IOException("" + sqle).initCause(sqle);
> }
> </pre>
>
> Since initCause returns a Throwable, it will usually cause compilation
> problems if not recast; and declaring your method as throws Throwable
> defeats the purpose of chained exceptions.
Yeah, you are right. This shows again why you should always let a compiler
check all your code even example code snippits. Thanks I have fixed it in
my tree (not yet comitted since I don't have it working with any VM yet).
> (As a side note, ""+obj is easier to type than obj.toString(), and has the
> added benefit of being null-pointer safe.
It is not really necessary here since this is in a catch clause which means
that the variable can never be null (if you try to throw a null object
reference then the VM should make sure to throw an explicit
NullPointerException).
Cheers,
Mark
--
Stuff to read:
<http://www.toad.com/gnu/whatswrong.html>
What's Wrong with Copy Protection, by John Gilmore