d模板化异常
auto contextWithException(T, E)(lazy scope T expression, Exception delegate(E) handler)
{
Exception newException;
try
{
return expression();
}
catch (E e)
{
newException = handler(e);
}
throw newException;
}
等价于:
return s
.readText
.parseJSON
.contextWithException((UTFException e) {
return new Exception("Cannot process UTF-8 in config file%s\n %s".format(s, e.msg), e);
})
.contextWithException((FileException e) {
return new Exception("Cannot process config file%s\n %s".format(s, e.msg), e);
});