gnu-arch-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gnu-arch-users] Nit


From: zander
Subject: Re: [Gnu-arch-users] Nit
Date: Tue, 21 Oct 2003 19:40:16 +0200

On Tue, Oct 21, 2003 at 09:11:15AM -0700, Tom Lord wrote:
> 
>     > Java programmers should never catch Exception, print nothing and
>     > do nothing with the exception.  Bad idea.
> 
> By default, they should catch Exception all over the place and abort
> -- letting through only those exceptions they explicitly intend to.
> The language should be extended with syntax to make that easy.

A part you seem to miss is that catching is part of the language and
you can catch seperate exceptions via seperate catch lines, meaning
that letting through is quite simple.
An example speaks more then anything:
To let through ExceptionA by not catching it.

    myMethod() throws ExceptionA {
        try {
            foo(); // this method is defined to throw 4 different Exceptions
        } catch(ExceptionB e) {
            // do something.
        } catch(ExceptionC e) {
            // do something.
        } catch(ExceptionD e) {
            // do something.
            throw new ExceptionA(e.getMessage());
        }
    }

I'm not sure what yo mean by 'abort', but if you in any method feel you should
exit the application due to a bad state; then you lost.  Exceptions are used
to never get into such a state.

As an example I wrote an application that fetches data from the network and
writes it to disk after doing some algoritms on it.  Due to the structure
(loads of classes and many many layers) the method doing the actual write
has a stackdepth of about 15 calls.
The wanted effect is that the failure is handled by the top-level call
printing an error.  To get there I added 'throws IOException' to all those
methods that don't want to deal with the problem, but are aware that at one
point below they can trigger that exception.

You see; exception handling is just about flow-control.

-- 
Thomas Zander

Attachment: pgpG2SzDZvFNU.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]