Thread overview | |||||
---|---|---|---|---|---|
|
February 12, 2011 assert(expression, error) | ||||
---|---|---|---|---|
| ||||
Hello,
Is there a way to specify what error to throw using (a variant of) assert:
assert(n > 0, new ValueError("..."));
(Sure, one can write:
if (n <= 0)
throw new ValueError("..."));
but the same remark applies to plain assert: the whole point of assert is to have it as builtin feature with clear application field & well-known semantics, shared by the community of D programmers.)
Denis
--
_________________
vita es estrany
spir.wikidot.com
|
February 12, 2011 Re: assert(expression, error) | ||||
---|---|---|---|---|
| ||||
Posted in reply to spir | spir napisał: > Is there a way to specify what error to throw using (a variant of) assert: > assert(n > 0, new ValueError("...")); > > (Sure, one can write: > if (n <= 0) > throw new ValueError("...")); > but the same remark applies to plain assert: the whole point of assert is to > have it as builtin feature with clear application field & well-known semantics, > shared by the community of D programmers.) With built-in assert, no. But std.exception can do it. enforce(n > 0, new ValueError("...")); -- Tomek |
February 12, 2011 Re: assert(expression, error) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | On 2011-02-12 10:05:34 -0500, Andrej Mitrovic <andrej.mitrovich@gmail.com> said: > Btw, is the inline problem just a DMD implementation problem, or does > enforce have to be fixed for that? DMD implementation problem. The inliner doesn't support ref, out, lazy, and delegate arguments at this time. Enforce uses a lazy second argument so it doesn't get inlined. -- Michel Fortin michel.fortin@michelf.com http://michelf.com/ |
Copyright © 1999-2021 by the D Language Foundation