From 807340bcd7717c018fbdf3e1b3b7fb3dd718e1ff Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Sat, 11 Feb 2023 14:15:10 +0100 Subject: [PATCH] CsvTxImpProps - simplify exception handling - catch multiple exception types in one block the exception handling code was the same anyway - stop rethrowing the exception. The calling code doesn't need this and just ignores it. --- .../csv-imp/gnc-imp-props-tx.cpp | 45 ++----------------- 1 file changed, 3 insertions(+), 42 deletions(-) diff --git a/gnucash/import-export/csv-imp/gnc-imp-props-tx.cpp b/gnucash/import-export/csv-imp/gnc-imp-props-tx.cpp index de0a168c09..db05b2e5e4 100644 --- a/gnucash/import-export/csv-imp/gnc-imp-props-tx.cpp +++ b/gnucash/import-export/csv-imp/gnc-imp-props-tx.cpp @@ -285,37 +285,22 @@ void GncPreTrans::set (GncTransPropType prop_type, const std::string& value) break; } } - catch (const std::invalid_argument& e) + catch (const std::exception& e) { auto err_str = (bl::format (std::string{_("{1}: {2}")}) % std::string{_(gnc_csv_col_type_strs[prop_type])} % e.what()).str(); m_errors.emplace(prop_type, err_str); - throw std::invalid_argument (err_str); - } - catch (const std::out_of_range& e) - { - auto err_str = (bl::format (std::string{_("{1}: {2}")}) % - std::string{_(gnc_csv_col_type_strs[prop_type])} % - e.what()).str(); - m_errors.emplace(prop_type, err_str); - throw std::invalid_argument (err_str); } } void GncPreTrans::reset (GncTransPropType prop_type) { - try - { set (prop_type, std::string()); - } - catch (...) - { // Set with an empty string will effectively clear the property // but can also set an error for the property. Clear that error here. m_errors.erase(prop_type); - } } StrVec GncPreTrans::verify_essentials (void) @@ -521,36 +506,21 @@ void GncPreSplit::set (GncTransPropType prop_type, const std::string& value) break; } } - catch (const std::invalid_argument& e) + catch (const std::exception& e) { auto err_str = (bl::format (std::string{_("{1}: {2}")}) % std::string{_(gnc_csv_col_type_strs[prop_type])} % e.what()).str(); m_errors.emplace(prop_type, err_str); - throw std::invalid_argument (err_str); - } - catch (const std::out_of_range& e) - { - auto err_str = (bl::format (std::string{_("{1}: {2}")}) % - std::string{_(gnc_csv_col_type_strs[prop_type])} % - e.what()).str(); - m_errors.emplace(prop_type, err_str); - throw std::invalid_argument (err_str); } } void GncPreSplit::reset (GncTransPropType prop_type) { - try - { set (prop_type, std::string()); - } - catch (...) - { // Set with an empty string will effectively clear the property // but can also set an error for the property. Clear that error here. m_errors.erase(prop_type); - } } void GncPreSplit::add (GncTransPropType prop_type, const std::string& value) @@ -598,21 +568,12 @@ void GncPreSplit::add (GncTransPropType prop_type, const std::string& value) break; } } - catch (const std::invalid_argument& e) + catch (const std::exception& e) { auto err_str = (bl::format (std::string{_("{1}: {2}")}) % std::string{_(gnc_csv_col_type_strs[prop_type])} % e.what()).str(); m_errors.emplace(prop_type, err_str); - throw std::invalid_argument (err_str); - } - catch (const std::out_of_range& e) - { - auto err_str = (bl::format (std::string{_("{1}: {2}")}) % - std::string{_(gnc_csv_col_type_strs[prop_type])} % - e.what()).str(); - m_errors.emplace(prop_type, err_str); - throw std::invalid_argument (err_str); } }