pspp-dev
[Top][All Lists]
Advanced

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

Re: Error messages again


From: Ben Pfaff
Subject: Re: Error messages again
Date: Thu, 18 May 2006 17:19:06 -0700
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux)

John Darrington <address@hidden> writes:

> On Thu, May 18, 2006 at 08:46:02AM -0700, Ben Pfaff wrote:
>      >
>      > /* Returns TRUE if error matches domain and code, FALSE otherwise. */
>      > gboolean    g_error_matches                 (const GError *error,
>      >                                              GQuark domain,
>      >                                              gint code);
>      >
>      > So the (domain, code) pair should be unique.
>      
>      OK.  But how would a pair of matching messages be treated
>      differently from a pair of differing messages, and does the
>      difference in treatment warrant actually trying to make them
>      unique?
>
>
> It's the glib way of implementing something akin to exception
> handling.  

[...]

> gboolean
> my_other_function_that_can_fail(GError **err2)
> {
>   GError *err = NULL;
>   my_function_that_can_fail(&err);
>
>
>   if (g_error_matches (err, THIS_DOMAIN, THIS_CODE))
>     {
>       handle_the_mess();
>       g_clear_error(&err);
>       return TRUE;
>     } 
>   else
>     {
>       g_propogate_error(err2, err);
>       g_clear_error(&err);
>       return FALSE;
>     }
> }

If this is the usage then it seems to me that you only need a
unique code for the errors you want to special-case this way.
You can use a generic code for other errors.

How often do you want to special-case errors this way?  What
situations have come up so far?

>      >      > I'm not sure how we'd implement that.  One idea would be to  
> have it
>      >      > initialsed whenever the function msg is called: Change msg to a 
> macro,
>      >      > and initialise code to a hash of the __FILE__, __LINE__ 
> combination.
>      
>      
>      I'd suggest initializing "code" as a hash of the message text.  I
>      don't know whether, e.g. "ABC is an unknown identifier." and "XYZ
>      is an unknown identifier." are different messages, so we could
>      try to get the hash before the formatting takes place, so that it
>      would actually be a hash of "%s is an unknown identifier."
>
> The problem with that approach, is that it would fall down with
> internationalisation,  since the translated string would have a
> different hash to the English one.

OK.
-- 
"Mon peu de succès près des femmes est toujours venu de les trop aimer."
--Jean-Jacques Rousseau




reply via email to

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