Skip to content

Commit

Permalink
Catch exceptions by const reference
Browse files Browse the repository at this point in the history
Especially don't catch the polymorphic std::exception by value,
which gave a warning.
  • Loading branch information
frankosterfeld authored and wirew0rm committed Apr 25, 2024
1 parent 391e0e5 commit 33596c9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions core/include/gnuradio-4.0/Block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,9 @@ class Block : public lifecycle::StateMachine<Derived>, //
} else { // function not declared with 'noexcept' -> may throw
try {
return std::forward<TFunction>(func)(std::forward<Args>(args)...);
} catch (gr::exception e) {
} catch (const gr::exception &e) {
emitErrorMessageIfAny(callingSite, std::unexpected(gr::Error(std::move(e))));
} catch (std::exception e) {
} catch (const std::exception &e) {
emitErrorMessageIfAny(callingSite, std::unexpected(gr::Error(e, location)));
} catch (...) {
emitErrorMessageIfAny(callingSite, std::unexpected(gr::Error("unknown error", location)));
Expand Down
4 changes: 2 additions & 2 deletions core/include/gnuradio-4.0/CircularBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ class double_mapped_memory_resource : public std::pmr::memory_resource {
for (int retry_attempt = 0; retry_attempt < 3; retry_attempt++) {
try {
return do_allocate_internal(required_size, alignment);
} catch (std::system_error& e) { // explicitly caught for retry
} catch (const std::system_error& e) { // explicitly caught for retry
fmt::print("system-error: allocation failed (VERY RARE) '{}' - will retry, attempt: {}\n", e.what(), retry_attempt);
} catch (std::invalid_argument& e) { // explicitly caught for retry
} catch (const std::invalid_argument& e) { // explicitly caught for retry
fmt::print("invalid_argument: allocation failed (VERY RARE) '{}' - will retry, attempt: {}\n", e.what(), retry_attempt);
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/include/gnuradio-4.0/Tag.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct alignas(hardware_constructive_interference_size) Tag {
get(const std::string &key) const noexcept {
try {
return map.at(key);
} catch (std::out_of_range &e) {
} catch (const std::out_of_range &e) {
return std::nullopt;
}
}
Expand All @@ -108,7 +108,7 @@ struct alignas(hardware_constructive_interference_size) Tag {
get(const std::string &key) noexcept {
try {
return map.at(key);
} catch (std::out_of_range &) {
} catch (const std::out_of_range &) {
return std::nullopt;
}
}
Expand Down

0 comments on commit 33596c9

Please sign in to comment.