Sign in to follow this  
nimnimnim

pretty way to throw/assertfail/etc with message.. or have VS spell out thrown text?

Recommended Posts

m$'s implementation of the stl classes makes use of some _Debug_message function (through _DEBUG_ERROR macro declared in xutility) which makes the errors assert-failed or thrown (?) from those classes spelled out at the first prompt. I'd like to keep my code iso c++ though etc.. when I'm not really sure which of two adjacent lines with throw statements produced the throw I may think an assert(<failing condition> && "message"); would make life easier.. but it's not very pretty. what's your way to do this to have it both standard and handy? I was going to give up pretentions and just tentatively define a MY_DEBUG_ERROR _DEBUG_ERROR of m$' but then I couldn't get it to resolve _Debug_message so gave up for today.. [Edited by - nimnimnim on May 12, 2008 4:57:15 PM]

Share this post


Link to post
Share on other sites
Here are some debug macros I wrote a while back, you may find them useful:


/* Variadic macros are only supported in Visual Studio 2005 (VC8) and GCC 3.0.0 or greater */
#if (_MSC_VER >= 1400 || __GNUC__ >= 3)
#define DEBUG_STRING(...) std::fprintf(stderr, __VA_ARGS__)
#define DEBUG_STRING_V(fmt,...) std::fprintf(stderr, "%s:%d: "fmt, __FILE__, __LINE__, ##__VA_ARGS__)
#else
//#error "Your compiler doesn't support variadic macros"
#define DEBUG_STRING
#define DEBUG_STRING_V
#endif




Though I'd advise you to use them with restraint. They should only be used when you don't have any other choice. For example, they're great to use in kernel programming, because there aren't many debugging options.

Share this post


Link to post
Share on other sites
thanks for the code example :)
I was (ambiguously) refering to producing a process halting error with a message that'd be shown in the error prompt that pops up in Visual Studio though but I appreciate this example too :) and I didn't know you could have variadic macros already :-o7

still interested in a non m$-pimped version of the _Debug_message of m$' stl implementation.

using assert(fail && "...") meanwhile which is ok as long as you use JIT.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this