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: Colin Walters
Subject: Re: GError (Re: [Gnu-arch-users] "librifying" libarch)
Date: Mon, 20 Oct 2003 19:48:49 -0400

On Mon, 2003-10-20 at 16:58, Tom Lord wrote:
>     > From: Colin Walters <address@hidden>
> 
> This is a "coding style" issue, not something where there's absolute
> perfect arguments that objectively prove one approach is better than
> another.   

Yep.

> I don't know what you mean by this "which layer" stuff.   The GError
> documentation talks about domain indicating a "module" and I don't
> know that they mean either.

A module is a component of a software system.  They may be layered, or
they may not be.

> I'm horrified to think that if I have a layered software system with
> layers: [...]
> 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.

Not necessarily.  For example, suppose C is a sort of filesystem
abstraction layer.  B is some sort of file parser or something.  You may
want to handle the cases where C fails differently from where B fails. 
For example, if C fails, you may want to ask the user to check their
network connection.  If B fails, you might ask the user if they want to
try recovering the file.

In a language like Java, this would be the equivalent of:

try {
  com.example.b.doFoo(...);
} except (com.example.b.InvalidFileException e) {
  ...
} except (com.example.c.NetworkResetException e) {
  ...
}

And that makes a lot of sense from an engineering standpoint.

> GError is a sort-of-ok debugging aid, but there are plenty of
> altnerative ways to debug things that don't require ->domain and
> ->code. 

The usage I gave above is the primary one, but debugging is also nicer. 
For example, when you print an error you can also print the module it
comes from.  I do this in Rhythmbox, so you might see e.g.:

** Gtk-WARNING: Foo is on crack
** RhythmDB-ERROR: Database is corrupted!

>            Heck, there's a much simpler solution that's just 
>            as good as domain+code:
> 
>               typedef char * arch_error_t;

You couldn't do what I'm talking about above with this approach.

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

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