C++ error with line of code

Started by
4 comments, last by Zoner 12 years, 10 months ago
I guess you've all seen c++ apps that display an error along with the line of code that causes it. It's usually used in games, but other apps use it, too.
I heard that this can be implemented using macros, but I can't seem to find any resource on the interwebs.
Anyone has any ideas how this is implemented?
Advertisement
http://gcc.gnu.org/onlinedocs/gcc-3.1.1/cpp/Standard-Predefined-Macros.html

I guess you've all seen c++ apps that display an error along with the line of code that causes it. It's usually used in games, but other apps use it, too.
I heard that this can be implemented using macros, but I can't seem to find any resource on the interwebs.
Anyone has any ideas how this is implemented?


are you talking about assertion failed errors ?

those are caused by the assert macro (which basically takes an expression, if it evaluates to true nothing happens, if it evaluates the false the program displays an error and exits) , normally those aren't used in release builds though. (most assert macros are written so that they'll be automatically stripped out unless its a debug build)
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

http://gcc.gnu.org/o...ned-Macros.html


Thanks, exactly what I was looking for :D

[quote name='Tayron' timestamp='1308127313' post='4823535']
I guess you've all seen c++ apps that display an error along with the line of code that causes it. It's usually used in games, but other apps use it, too.
I heard that this can be implemented using macros, but I can't seem to find any resource on the interwebs.
Anyone has any ideas how this is implemented?


are you talking about assertion failed errors ?

those are caused by the assert macro (which basically takes an expression, if it evaluates to true nothing happens, if it evaluates the false the program displays an error and exits) , normally those aren't used in release builds though. (most assert macros are written so that they'll be automatically stripped out unless its a debug build)
[/quote]

For a large commerical game that is performance intensive maybe. But often times it is helpful to leave asserts in the release build. I've had cases where I could fix bugs because users reported an assertion failure. Without asserts it would be significantly harder, if at all possible to locate such bugs. I'd say when in doubt, leave them in.
I trust exceptions about as far as I can throw them.
You can more or less automate a crash log by walking the stack, and providing some (at a minimum c++ public symbols). If there is enough information avialable to the debug API's (via pdb files, access to microsoft's symbol servers, your own symbol server etc), you will get line numbers, function names, and other juicy details.

http://stackwalker.codeplex.com/


You basically need to have all your exception classes walk the stack with the code I linked above in their constructors, and also hook up a SEH handler filter to catch system exceptions (access violation, divide by zero, etc), and dump the stack in there too. It is quite useful as end-user call stacks can vary quite a bit due to the presence of other DLLs on the system.
http://www.gearboxsoftware.com/

This topic is closed to new replies.

Advertisement