digitalmars.D.learn - assert(expression, error)
- spir (14/14) Feb 12 2011 Hello,
- Tomek =?ISO-8859-2?Q?Sowi=F1ski?= (7/16) Feb 12 2011 ntics,=20
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
Feb 12 2011
spir napisa=B3:Is there a way to specify what error to throw using (a variant of) assert: assert(n > 0, new ValueError("...")); =20 (Sure, one can write: if (n <=3D 0) throw new ValueError("...")); but the same remark applies to plain assert: the whole point of assert is=to=20have it as builtin feature with clear application field & well-known sema=ntics,=20shared by the community of D programmers.)With built-in assert, no. But std.exception can do it. enforce(n > 0, new ValueError("...")); --=20 Tomek
Feb 12 2011