Skip to content

Commit af94aa9

Browse files
author
kopturovdim
committed
feat userver: cusom exception for FromString
Tests: unittests commit_hash:df1a08db1791e46067bcbd5075ebc6e7ed7d702b
1 parent e74e518 commit af94aa9

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

universal/include/userver/utils/from_string.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ USERVER_NAMESPACE_BEGIN
2222

2323
namespace utils {
2424

25+
class FromStringException : public std::runtime_error {
26+
public:
27+
using std::runtime_error::runtime_error;
28+
};
29+
2530
namespace impl {
2631

2732
template <typename T, typename = void>

universal/src/utils/from_string.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace impl {
1414

1515
[[noreturn]] void
1616
ThrowFromStringException(std::string_view message, std::string_view input, std::type_index result_type) {
17-
throw std::runtime_error(fmt::format(
17+
throw FromStringException(fmt::format(
1818
R"(utils::FromString error: "{}" while converting "{}" to {})",
1919
message,
2020
input,

universal/src/utils/from_string_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ std::string ToString(T value) {
3232

3333
template <typename T>
3434
auto TestInvalid(const std::string& input) {
35-
ASSERT_THROW(utils::FromString<T>(input), std::runtime_error)
35+
ASSERT_THROW(utils::FromString<T>(input), utils::FromStringException)
3636
<< "type = " << compiler::GetTypeName<T>() << ", input = \"" << input << "\"";
3737
}
3838

@@ -227,7 +227,7 @@ TYPED_TEST(FromStringTest, ExceptionDetails) {
227227

228228
try {
229229
utils::FromString<T>(".blah");
230-
} catch (const std::runtime_error& e) {
230+
} catch (const utils::FromStringException& e) {
231231
what = e.what();
232232
} catch (const std::exception& e) {
233233
// swallow

0 commit comments

Comments
 (0)