Unit tests in D

bearophile bearophileHUGS at lycos.com
Wed May 5 04:46:46 PDT 2010


Michel Fortin:

> Can't you do:
> 	static assert(throws!OtherException(sqrt(-5)));
> ?

Some of those examples of mine were wrong because the main purpose of a 'static throws' is to catch static asserts, not to catch exceptions at compile time, sorry:
static throws(foo(10), StaticException1);
static throws(foo(10), StaticException1, StaticException2, ...);
static throws!(StaticException1)(foo(10));
static throws!(StaticException1, StaticException2)(foo(10));

(And currently try-catch statements are not supported in CTFE, see http://d.puremagic.com/issues/show_bug.cgi?id=4067 ).

Bye,
bearophile


More information about the Digitalmars-d mailing list