DMD 1.027 and 2.011 releases
Charles D Hixson
charleshixsn at earthlink.net
Fri Feb 29 16:55:47 PST 2008
eao197 wrote:
> On Thu, 28 Feb 2008 19:34:45 +0300, Russell Lewis
> <webmaster at villagersonline.com> wrote:
>
>>> It is not necessary to catch AssertError. Sometimes it is necessary
>>> to catch any error. For example, in a HTTP-server you could start
>>> processing of a new request and catch different kinds of errors to
>>> make appropriate response:
>>
>> I agree that a web server needs to post an appropriate response. But
>> if an assert() has failed, you don't know if the failure is in your
...
>
> For example, SMS body in 140 bytes long. 7-bit message could be up to
> 160 symbols, packed into 140 bytes SMS body. You could have 7-bit
> message packing functions with precondition:
>
> byte[] pack7bitMessage( byte[] message )
> in { assert( message.length <= 160 ); }
> body { ... }
>
...
I think you are misunderstanding the purpose of assert and of
other conditions. Remember, these statements will be stripped
out of the code when it is compiled for release. As such,
they should only be used to detect conditions which are
genuine errors. The reason that they might be cause would be
so that the actual error could be raised from the location
where the error is generated, rather than from where it was
detected.
In Other Words: Don't use contracts as a substitute for
conditionals, even if the conditional *would* raise an
exception. They aren't the same concept.
Now I'll grant that in some languages the two concepts are
fused, and conditionals are constrained to do double duty as
exceptions. Even in those languages, however, there is often
a flag that will cause assertions to become null statements
when compiled with optimization (or without debugging turned on).
[N.B.: The prior paragraph is based on certain dialects of C
or C++ that are over a decade old now. It may not apply to
currently extant compilers.]
More information about the Digitalmars-d-announce
mailing list