Problem collecting exception from a passed function
Gary Willoughby
dev at nomad.so
Tue Nov 26 13:04:30 PST 2013
Figured it out. When using lazy don't pass as a pointer and call
at the caller site. The argument is then lazily evaluated by the
called function and not by the caller. This enables passing
parameters at the caller site too.
import std.exception;
import std.stdio;
public void foo(A : Exception, B)(lazy B func)
{
auto exception = collectException(func());
writefln("%s", exception.msg);
}
void bar()
{
throw new Exception("This is thrown");
}
void main(string[] args)
{
foo!(Exception)(bar());
}
More information about the Digitalmars-d-learn
mailing list