Re: let g_warn_if_fail replace g_assert

Tim Janik wrote:
> hey All.
> proposing to turn g_asert into a warning:
> was obviously not perceived too well.
> as i read it, most people are not against my basic
> reasoning, but are clearly in favour of adding
> g_warn_if_fail or a similar variant thereof.

Is g_warn_if_fail() useful at all? It would be nice to have a macro
which would warn *and* do something, like g_return_if_fail. I can't
imagine what syntax it would have, perhaps some
g_make_sure(a=2, {g_free(something); return;})
(it does look stupid, and it does look like a silly attempt to have nice
error handling in C), but I can't imagine how g_warn_if_fail is useful.
In what situations would it be used? Replacing

if (!foo)
  g_warning ("oops");


g_warn_if_fail (a != NULL, "oops");

is nice but not too nice. Perhaps the problem is that this discussion
as a talk about g_assert and g_return_if_fail, which handle critical
errors and
performs some actions - killing the application or jumping out the
So it's not clear if g_warn_if_fail() is comparable at all (I guess it's
just a totally
different thing). Would you write code like

g_warn_if_fail (something);
/* proceed like nothing bad happened */

If something happened bad enough to warn about it, then you probably also
need to perform some action - do something different in an if() branch, or
return from the function, or something. But then if you do have that
if(), then
you could just use g_warning().
(I am not stating that g_warn_if_fail() is bad or not needed, just
trying to
understand what exactly it's for)

Best regards,

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