@trust is an encapsulation method, not an escape

Vladimir Panteleev via Digitalmars-d digitalmars-d at puremagic.com
Fri Feb 6 21:49:22 PST 2015


On Friday, 6 February 2015 at 21:08:21 UTC, Walter Bright wrote:
> 1. exceptions are not for debugging the logic of your program
> 2. do not use exceptions to recover from logic bugs in your 
> program

OK, this is nothing new, but still doesn't answer my question.

Would you say that the correct thing to do, then, would be an 
unconditional check that throws an Error? Such as, `if (!...) 
throw new Error(...)`, or `enforce!Error(...)`?

I recall there is a bug report on Bugzilla that Phobos contracts 
are removed in release (default) builds of the library, when 
ideally contracts of public functions should stay but inner 
asserts should be removed in optimized code. That would allow 
using them for validating parameters without resorting to 
explicitly-unconditional checks.


More information about the Digitalmars-d mailing list