Hmmm... There was a discussion all the way back in 2008 where I was wanting to get better error messages out of libMesh... and Roy shot me down ;-)

Instead of specialized assert functions like this (have you been spending too much time with cpp_unit?? ;-) why not just make libmesh_assert() take a string that gets printed if the assert is false.  This is what we do in MOOSE... for errors, asserts and warnings and it works great.

Here are our current error / assert / warning functions for reference:


#ifdef GRACEFUL_ERROR
#define mooseError(msg) do { std::cerr << "\n\n" << msg << "\n\n"; print_trace(); exit(1); } while(0)
#else
#define mooseError(msg) do { std::cerr << "\n\n" << msg << "\n\n"; print_trace(); libmesh_error(); } while(0)
#endif

#ifdef NDEBUG
#define mooseAssert(asserted, msg)
#else
#define mooseAssert(asserted, msg)  do { if (!(asserted)) { std::cerr << "\n\nAssertion `" #asserted "' failed\n" << msg << "\nat " << __FILE__ << ", line " << __LINE__ << std::endl; print_trace(); libmesh_error(); } } while(0)
#endif

#define mooseWarning(msg) do { std::cerr << "\n\n*** Warning ***\n" << msg << "\nat " << __FILE__ << ", line " << __LINE__ << "\n" << std::endl; } while(0)


On Wed, Sep 12, 2012 at 6:40 PM, Roy Stogner <roystgnr@ices.utexas.edu> wrote:

On Fri, 18 May 2012, Roy Stogner wrote:

> Would it make sense to have a few variant macros for common assertion
> cases, so that when those (debug+devel-mode) assertions get tripped we
> can immediately print more information about the failure?
>
> E.g. whereas
>  libmesh_assert(a < b);
> fails with an error message like
>  Assertion `a < b' failed
> the variant
>  libmesh_assert_less(a,b);
> could fail with an error message like
>  Assertion `a < b' failed: `a' = 3, `b' = 2

This is now done, but needless to say the diff which actually converts
assertions to use the more detailed macros is huge.

I'm posting it to http://users.ices.utexas.edu/~roystgnr/asserts_patch
for now; hopefully it can get some wider testing before going into
trunk, especially considering it's about 10% hand-edited and 90%
regex'ed.

This may also be the last straw for me to create a "testing" branch.
---
Roy

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Libmesh-devel mailing list
Libmesh-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libmesh-devel