On Fri, 19 Nov 2004 23:31:11 -0800, Craig McClanahan <[EMAIL PROTECTED]> wrote:
> On Fri, 19 Nov 2004 23:21:02 -0800, Daniel Rall <[EMAIL PROTECTED]> wrote:
> 
> 
> > On Fri, 2004-10-29 at 13:35 -0400, Henri Yandell wrote:
> > ...
> > > How about just being able to do multiple Exceptions in one block?
> > >
> > > try {
> > >      ....
> > > } catch(JMSException, RemoteException, SQLException e) {
> > > }
> > >
> > > or possibly even:
> > >
> > > try {
> > >      ....
> > > } catch( (JMSException | RemoteException | SQLException) e) {
> > > }
> >
> > Something like this would be truly excellent.  I'm so sick of having to
> > write 30 lines of exception handling code.
> 
> How about two lines, which you can already do today?

That might catch all the exceptions I am expecting, but it will also
catch any exceptions that I am not expecting. Thus the behaviour I
code into the catch clause here might be totally inappropriate for
some of the exceptions it ends up catching.

Also, the compiler will not help me discover that the methods that I
am calling have changed the exceptions that they throw, meaning that
the catch clause is even more likely to become inappropriate over
time.

Finally, I have now lost the self-documenting characteristics of
explicitly naming the exception types I am catching.

At my current company, and at my last company, we have coding
guidelines that explicitly ban the use of what you suggest, for the
reasons above.

Having had the ability to do (the first of) what Henri suggests in
other programming languages in the past, I would be very much +1 on
that inclusion in Java. :-)

--
Martin Cooper


> 
> try {
>  ...
> } catch (Exception e) {
>  ...
> }
> 
> If you really want to treat different types of exceptions differently,
> you can special case by putting specialized catch blocks for the
> special cases in front of this.  The predominant use case, though,
> seems to be a standarized "log it and exit" or "log it and rethrow it
> in a wrapper exception" strategy, which you can deal with quite
> easily.
> 
> Sheesh, hasn't anyone ever heard of inheritance around here?  :-)
> 
> Craig
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to