Quote:Original post by Jaapio
Quote:Original post by Lajnold
Quote:Original post by Jaapio
Assert??? (sounding like a complete idiot)
Sorry I have never heard of that term?
http://www.cppreference.com/stdother/assert.html
#include <cassert>assert(ptr != 0);
For as far as I can see now assert is ugly.
If the term evaluates false you get an ugly dialogbox.
No thanks Id rather check with an if statement.
It's a debug tool. You should use it for things that should never cause you to see the dialog box. Consider it's ugliness punishment for screwing up when you do see it. Note that assert(x) also will not evaluate x unless _DEBUG is #defined, which means these checks are typically removed from Release builds.
(Or is that "will not evaluate x if NDEBUG is #define"d? I forget.)
It also has the nice property of stopping your debugger on the appropriate line, in anything half resembling a development environment.
Quote:There must be a way to catch those exceptions too.
I mean the watch does not explode when I have it evaluate a something invalid.
There is, in a manner of speaking. Typically, though, when these errors occur, you've already massively fucked up, and things may not be salvageable. Since your debugger needs to hook into the other applications address space and whatnot to evaluate watches and so forth, the debugger manages to limit such explosions to the program being debugged.
But if you really want to shoot your foot off like that, google "SEH Exceptions". Note that they're compiler extensions, not ISO C++, as the only thing the C++ standard requires is... well, nothing. The standard allows the implementation to launch nuclear missiles at a cow ranch in alaska at this point. If you're programming control software for nuclear silos, I'd even go so far as to say that this is a likely, eventual outcome.