[Gtk-sharp-list] Gdk.Color, further comments.

Charles Iliya Krempeaux charles@reptile.ca
03 Mar 2003 10:33:23 -0800


Hello,

On Mon, 2003-03-03 at 09:13, Miguel de Icaza wrote:
> Hello,
> 
> > > Throwing exceptions turns out to be very inefficient.   
> > 
> > Hmmm... so, with my GnomeVFS wrapper, would it be a
> > good idea to have GnomeVFSResult returned?  (Instead
> > of having it thrown, like I have now.)
> 
> Yes, you should return an error code (like most Gnome VFS routines do).

OK, now what about the implementation of the System.IO.Stream class,
using GnomeVFS.  For example, consider the implementation of the
"Close" method:

    using GnomeVFSResult = System.Int32;

    // ...

    private const GnomeVFSResult GnomeVFSResultOK = 0;

    // ...

    public override void Close()
    {
        GnomeVFSResult result = gnome_vfs_close(this.Handle);

        if (GnomeVFSResultOK != result) {
            throw new Gnome.VFS.Exception(result);
        }
    }

As you can see, there is no way to "return" the error.  So, currently,
I just throw it.  I could take an alternate approach.  (I could have
something like a "errno" in the class, and do stuff like this.)

    private GnomeVFSResult errno;

    // ...

    public override void Close()
    {
        this.errno = gnome_vfs_close(this.Handle);
    }

    public bool HadError {
        get {
            return (GnomeVFSResultOK != this.errno)
        }
    }

    public GnomeVFSResult Error {
        get {
            return this.errno;
        }
    }

And then, you'd do stuff like...

    Gnome.VFS.Stream stream;

    // ...

    stream.Close();
    if (stream.HadError) {

        switch (stream.Error) {
            // ...
        }
    }

What do you think?  Should I take this approach?  Should I take
another approach?  Or what?


See ya

-- 
     Charles Iliya Krempeaux, BSc
     charles@reptile.ca

________________________________________________________________________
 Reptile Consulting & Services    604-REPTILE    http://www.reptile.ca/