DIY checking exceptions
John Colvin via Digitalmars-d
digitalmars-d at puremagic.com
Mon Jun 26 14:53:57 PDT 2017
On Sunday, 25 June 2017 at 17:38:14 UTC, mckoder wrote:
> I am disappointed that D doesn't have checked exceptions.
I wonder what could be done with something like this:
void foo(int a)
{
if (a > 0)
throw new BlahException("blah");
throw new BloopException("bloop");
}
unittest
{
// NEW FEATURE HERE
alias Exceptions = __traits(thrownTypes, foo);
static assert (staticIndexOf!(BlahException, Exceptions) >=
0);
static assert (staticIndexOf!(BloopException, Exceptions) >=
0);
}
I'm imagining one could use that to do quite a lot of what
checked exceptions provide.
More information about the Digitalmars-d
mailing list