Public Group

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

This topic is 3783 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

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 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 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.

1. 1
2. 2
Rutin
21
3. 3
4. 4
frob
17
5. 5

• 9
• 12
• 9
• 33
• 13
• Forum Statistics

• Total Topics
632595
• Total Posts
3007266

×