glob2-devel
[Top][All Lists]
Advanced

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

Re: [glob2-devel] Error handling and reporting


From: Andrew Sayers
Subject: Re: [glob2-devel] Error handling and reporting
Date: Tue, 4 Oct 2005 14:29:36 +0100
User-agent: Mutt/1.5.11

On Tue, Oct 04, 2005 at 01:48:46PM +0200, Stephane Magnenat wrote:
> > Does anyone have any other suggestions about design goals?  I've been
> > thinking over implementations for days and haven't found anything I like
> > yet.  Does anyone know of a project that's done this well, which we can
> > borrow ideas from?
> 
> Yes, Stroustrup (C++'s creator) himself has similar critics towards assert in 
> one of the last chapters of his book 
> (http://www.research.att.com/~bs/3rd.html) about C++. He suggests a mechanism 
> based on template that throw exceptions. Even if his proposal does not adress 
> all your points, I think that it is nevertheless a good reading.
> 
> If you don't have access to this book, I could make you a summary (of the 
> templatised assert, not of the book ;-)). But this book is very usefull when 
> coding with C++ anyway. With it, you'll know why things are how they are, 
> it's a bit like having God telling you the ultimate reasons behind the whole 
> strange reality! :-)

Aha, a fellow disciple of Stroustroup!  For anyone else thinking about
getting a book on C++, I couldn't agree more - as well as being an
excellent language guide and reference, reading the book gives you a
deeper appreciation of the language (and programming in general),
often without you noticing.

Actually, his Assert<>() solution was the first thing I reached for when
I was thinking of new debugging mechanisms.  I've been debating with
myself a lot about whether I like it - for example, it doesn't make it
easy to implicitly pass __FILE__, __LINE__ etc. as part of an
assertion*.  Also, reading the chapter on exceptions got me thinking
about the point of classes with relation to exceptions.

Assert<>() might well be the starting point for handling assertions in
an appropriate way - in fact, I'm coming round to the idea again as I
write this - but I increasingly feel like there's more to it than that,
and we need a more general solution.

As I write this, the best solution I can think of is something like
this:

if MyDebugClass::Assert(assertion)
        Abort(myError) << data1 << data2;

Where "Abort()" is a macro defined something like:
#define Abort(A) Debug::Abort(A, __FILE__, __LINE__, __PRETTY_FUNCTION__)

That would meet most or all of my criteria, but it still means using
nasty macro magic.  Another possibility (just as nasty, but more
explicitly so) is:

if MyDebugClass::Assert(assertion)
        MyDebugClass::Abort(DEBUG_INFO, myError) << data1 << data2;

Where DEBUG_INFO is defined something like:
#define DEBUG_INFO __FILE__, __LINE__, __PRETTY_FUNCTION__

Actually, looking at it, that could be alright.  Then again, I'll
probably hate it by tonight.

        - Andrew

* ultimately, this is a language failing, and some googling turned up
  some official pondering about defining "__file__" and "__line__" to
  fix the problem (at the bottom of the file):
  http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1642.html




reply via email to

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