Re: a missing feature in VC debugger
On Sun, 9 Jul 2006 21:38:19 -0700, "Ed Weir \(ComCast\)" <Anon@Maus.duh>
wrote:
Using try/catch gives you the
opportunity to keep the crash under control in free builds.
If by "crash" you mean things like access violations due to dereferencing
null pointers, that is not what try/catch is for. Note that with VC2005, MS
finally has made a C++ compiler whose catch(...) doesn't catch untranslated
structured exceptions such as access violations when using the default
/EHsc option, and that's a very good thing.
So you wouldn't replace an assertion with try/catch. You might replace it
by testing a condition and throwing an exception, but that drastically
changes the semantics of the program. EH in C++ is about dealing with
errors that occur in correct programs, while assertions are concerned with
detecting bugs, which by definition don't exist in correct programs. So if
your function was previously undefined on null pointers, changing this:
void f(char* p)
{
assert(p != NULL);
}
to this:
void f(char* p)
{
if (p == NULL)
throw std::invalid_argument("null pointer");
}
represents a major change in the semantics of f. The second version is
defined on null pointers, and it throws std::invalid_argument when it gets
one.
--
Doug Harrison
Visual C++ MVP