On 18.06.21 14:40, vit wrote:
Are asserts enough to make method @trusted or is something like throw exception or return error code necessary?
Asserts are a debugging feature. They're not suitable to ensure safety, because they're simply skipped in release mode.

`assert(false);` is the exception. It aborts the program even in release mode. So you can use it to bail out when your expectations fail.

So:

assert(expected); /* Don't do this. */

import std.exception: enforce;
enforce(expected); /* Instead, do this */
if (!expected) throw new Exception("..."); /* or this */
if (!expected) assert(false); /* or this. */
  • @trusted methods vit via Digitalmars-d-learn
    • Re: @trusted methods ag0aep6g via Digitalmars-d-learn

Reply via email to