You talked about catching more than one exception at once using Java
Generics. Is there an example out there where I can see how exactly
that would be possible?
Thanks in advance,
Bernd
On Aug 9, 4:49 am, Bernd Schiffer <bernd.schif...@googlemail.com>
wrote:
try {
statementWithTwoCheckedExceptions();
} catch(Throwable<CheckedException1, CheckedException2> throwable) {
doSomethingWith(throwable);
Oh, I see - it's a pity :-) Would be nice if you'd write something like: try { statementWithTwoCheckedExceptions(); } catch(Throwable<CheckedException1, CheckedException2> throwable) { doSomethingWith(throwable); }
catch ( CheckedException1, CheckedException2 e )where the compiler was responsible for figuring out the most derived Throwable subclass shared by the exceptions listed.
{
...
}
Why not do a variation on the array syntax:
catch (new Throwabe[] {CheckedException1, CheckedException2}) {
...
}
If the language spec was then to take advantage of JDK5's optional parameters you could even drop the declaration back to
catch (CheckedException1, CheckedException2) {
...
}
catch (ExceptionType1 e)Of course that's not the worst thing to have to write -- it'd just be nicer not to have to go this far...
{
handleException( e );
}
catch (ExceptionType2 e )
{
handleException( e );
}
catch (ExceptionType3 e )
{
handleException( e );
}
...
void handleException( ExceptionBaseClass1 e )
throws SomeExceptionType
{
...
}
Interesting idea, but to me this whole thing smells like trying to
solve a problem that doesn't really exist.
Sergio
I couldn't find the link to the generics proposal the Posse mentioned
in the podcast.