From b86d8d0cd83c0646fb31013442579c5d4c26ceb8 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 29 May 2019 21:46:27 +0200 Subject: [PATCH] config/Param: add method ThrowWithNested() --- src/config/Param.cxx | 8 +++++++- src/config/Param.hxx | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/config/Param.cxx b/src/config/Param.cxx index e27059d70..97e600b44 100644 --- a/src/config/Param.cxx +++ b/src/config/Param.cxx @@ -24,13 +24,19 @@ #include +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(); } } diff --git a/src/config/Param.hxx b/src/config/Param.hxx index 9162ec4c6..05ca8cd04 100644 --- a/src/config/Param.hxx +++ b/src/config/Param.hxx @@ -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