config/Block: add method With()

This commit is contained in:
Max Kellermann 2019-05-29 22:34:39 +02:00
parent ece35552fe
commit 96a37da03d
1 changed files with 13 additions and 0 deletions

View File

@ -59,6 +59,19 @@ struct BlockParam {
*/
[[noreturn]]
void ThrowWithNested() const;
/**
* Invoke a function with the configured value; if the
* function throws, call ThrowWithNested().
*/
template<typename F>
auto With(F &&f) const {
try {
return f(value.c_str());
} catch (...) {
ThrowWithNested();
}
}
};
struct ConfigBlock {