assert(false)
Joseph Rushton Wakeling
joseph.wakeling at webdrake.net
Thu Jun 20 14:21:28 PDT 2013
On 06/20/2013 10:15 PM, Jonathan M Davis wrote:
> I definitely use assert(false) for what is supposed to be unreachable code. The
> two prime places that I can think of off the top of my head are
>
> 1. In a catch block when it's supposed to be impossible for the try block to
> throw (e.g. when calling format in a nothrow function, and you know that
> format won't throw with the arguments that you're passing it).
>
> 2. In the default case of a switch statement when the default case should be
> unreachable.
>
> If those ever _are_ reached, then your code has serious problems, and killing
> the program is almost certainly a good thing.
In my case it was a bunch of if/else where the program should return from one of
the blocks. I saw comparable cases in RandomCover with an assert(false) at the
very end of the function, so thought I'd better tweak my code accordingly.
More information about the Digitalmars-d-learn
mailing list