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

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

Re: GError (Re: [Gnu-arch-users] "librifying" libarch)


From: Thomas Zander
Subject: Re: GError (Re: [Gnu-arch-users] "librifying" libarch)
Date: Tue, 21 Oct 2003 10:39:47 +0200
User-agent: KMail/1.5

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Monday 20 October 2003 22:58, Tom Lord wrote:
> I'm horrified to think that if I have a layered software system with
> layers:
>
>
>       A       |
>       B       | calls
>       C       V
>
>
> that layer A can get back an error that is programmatically labeled as
> coming from layer C and try to handle it on that basis.   That's an
> abstraction violation:  A isn't supposed to know if or how B uses C.
> So, `domain' is just a pit of hell, here.

Maybe this (real life) example can make it clear to you why this conclusion 
is not entirely correct; (see code snippet at bottom)

domain a = main
domain b = fetcher.run
domain c = handleItem
if c writes to a file and finds out it can't write for some reason; domain b 
will never know about it and the error will be forwarded to domain a since 
it just stops the whole thing, i'm sure you can do a similar thing (the 
forwarding of errors to higher levels) not unlike Java.
Notice that IOException is not one explicit error; it is a wildcard that can 
mean various things; from permission problems to disk full problems.
In this case domain a should be able to figure out exactly what kind of 
error it gets since it has to identify it, and handle it correctly; all I 
do here is print it; but you can certainly think of nicer error handling 
ways that want to differentiate between out of disk space and permission 
problems, naturally I need to know the domain (core filesystem in this 
case) to be able to know what kind of exception I have here.

You also said:
>  A isn't supposed to know if or how B uses C. So, `domain' is just a
> pit of hell, here.
In the example case IOException is a generic exception that can be thrown by 
file writing software as well as network enabled software.  In both cases 
the domain is similar, but the exact number is different; I am aware that 
your solution does not allow you to use error handling like this; but the 
point should be clear.

main() {
        try {
                new Fetcher().run;
        } catch(IOException e) {
                print("Failed to write output files "+e);
        }
}

Fetcher.run() throws IOException {
        array = getAllJobs();
        foreach item in array {
                try {
                        handleItem(item)
                } catch(OrderProblem e) {
                        println("order failed");
                        item.setFailedReason(e.getMessage());
                }
        }
}

handleItem(Order item) throws IOExcepion, OrderProblem {
        if(order.bla)    throw OrderProblem("a Problem");
        writer.write(order.getName);   // write can throw an IOException
        writer.write(order.getAmount());
}

- -- 
Thomas Zander
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE/lPDTCojCW6H2z/QRAvwlAKDoKNEvHi/SWlULqzDcCiyJyD8MQwCdEe5c
GHry2/XxlzrLJICO26bKz04=
=Ijoa
-----END PGP SIGNATURE-----




reply via email to

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