[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Error messages again
From: |
John Darrington |
Subject: |
Re: Error messages again |
Date: |
Fri, 19 May 2006 07:27:07 +0800 |
User-agent: |
Mutt/1.5.9i |
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. For example I can cascade function calls thus:
gboolean
my_function_that_can_fail (GError **err)
{
g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
if (!sub_function_that_can_fail (err))
{
/* assert that error was set by the sub-function */
g_assert (err == NULL || *err != NULL);
return FALSE;
}
/* otherwise continue, no error occurred */
g_assert (err == NULL || *err == NULL);
}
and I can handle the specific failures and pass the others to the next
stack frame :
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;
}
}
> > 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.
J'
--
PGP Public key ID: 1024D/2DE827B3
fingerprint = 8797 A26D 0854 2EAB 0285 A290 8A67 719C 2DE8 27B3
See http://pgp.mit.edu or any PGP keyserver for public key.
signature.asc
Description: Digital signature