On Thursday, 1 November 2018 at 08:42:28 UTC, Don Clugston wrote:
Absolutely there is a reason. Exceptions are very expensive, especially in low-level functions.

Then I got a few follow-up questions (I hope this isn't the wrong place for beginner questions): 1. Why is it that arrays throw RangeExceptions? Shouldn't that be too costly too? 2. I might be wrong but I thought that in the following code example the additional cost is only the cost of one additional branch from the if statement, unless of course i >= length which should never happen.

if (i < length)
{
    //do something
}
else
{
    throw new Exception();
}


3. When exceptions can't be used, then I guess the best way to ensure safety are pre and post contracts. But I actually don't know how to activate the contracts in phobos.
I thought that maybe I have to build both phobos and dmd with

$make -f posix.mak -j8 BUILD=debug

but I just tried that and I don't think it worked.
_______________________________________________
phobos mailing list
[email protected]
http://lists.puremagic.com/mailman/listinfo/phobos

Reply via email to