runtime hook for Crash on Error
Jonathan M Davis
jmdavisProg at gmx.com
Fri Jun 1 12:38:47 PDT 2012
On Friday, June 01, 2012 14:00:01 deadalnix wrote:
> Le 01/06/2012 12:26, Walter Bright a écrit :
> > Except that you do not know why the arithmetic turned out wrong - it
> > could be the result of memory corruption.
>
> Yes. wrong calculation often comes from memory corruption. Almost never
> from programmer having screwed up in the said calculation.
>
> It is so perfectly reasonable and completely match my experience. I'm
> sure everybody here will agree.
>
> Not to mention that said memory corruption obviously come from compiler
> bug. As always. What programmer does mistakes in his code ? We write
> programs, not bugs !
I'd have to agree that the odds of an arithmetic error being caused by memory
corruption are generally quite low, but the problem is that when an assertion
fails, there's _no_ way for the program to know how bad things really are or
what the cause is. The programmer would have to examine the entire program
state (which probably still isn't enough in many cases, since you don't have
the whole history of the program state - only its current state) and the code
that generated the assertion in order to figure out what really happened.
When an assertion fails, the program has to assume the worst case scenario,
because it doesn't have the information required to figure out how bad the
situation really is. When you use an assertion, you're saying that if it
fails, there is a bug in your program, and it must be terminated. If you want
to recover from whatever the assertion is testing, then _don't use an
assertion_.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list