config/Param: add method ThrowWithNested()

This commit is contained in:
Max Kellermann 2019-05-29 21:46:27 +02:00
parent 0b4e7b3317
commit b86d8d0cd8
2 changed files with 15 additions and 1 deletions

View File

@ -24,13 +24,19 @@
#include <stdexcept>
void
ConfigParam::ThrowWithNested() const
{
std::throw_with_nested(FormatRuntimeError("Error on line %i", line));
}
AllocatedPath
ConfigParam::GetPath() const
{
try {
return ParsePath(value.c_str());
} catch (...) {
std::throw_with_nested(FormatRuntimeError("Invalid path at line %i: ", line));
ThrowWithNested();
}
}

View File

@ -58,6 +58,14 @@ struct ConfigParam {
* Throws #std::runtime_error on error.
*/
AllocatedPath GetPath() const;
/**
* Call this method in a "catch" block to throw a nested
* exception showing the location of this setting in the
* configuration file.
*/
[[noreturn]]
void ThrowWithNested() const;
};
#endif