From 78fdf09c69a890cb3893588ccb3c5bdb0bb0404c Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Tue, 2 Jul 2019 15:47:05 +0200 Subject: [PATCH] Catch specialized exceptions instead of generic xbt_ex. --- doc/doxygen/uhood_switch.doc | 19 ++++----- .../s4u-platform-failures.cpp | 14 ++----- src/msg/msg_comm.cpp | 39 +++++++------------ src/msg/msg_task.cpp | 15 ++----- 4 files changed, 28 insertions(+), 59 deletions(-) diff --git a/doc/doxygen/uhood_switch.doc b/doc/doxygen/uhood_switch.doc index 123a25d6d9..f9b3ad14e4 100644 --- a/doc/doxygen/uhood_switch.doc +++ b/doc/doxygen/uhood_switch.doc @@ -708,20 +708,15 @@ std::cv_status ConditionVariable::wait_for( simcall_cond_wait_timeout(cond_, lock.mutex()->mutex_, timeout); return std::cv_status::no_timeout; } - catch (xbt_ex& e) { - + catch (const simgrid::TimeoutError& e) { // If the exception was a timeout, we have to take the lock again: - if (e.category == timeout_error) { - try { - lock.mutex()->lock(); - return std::cv_status::timeout; - } - catch (...) { - std::terminate(); - } + try { + lock.mutex()->lock(); + return std::cv_status::timeout; + } + catch (...) { + std::terminate(); } - - std::terminate(); } catch (...) { std::terminate(); diff --git a/examples/s4u/platform-failures/s4u-platform-failures.cpp b/examples/s4u/platform-failures/s4u-platform-failures.cpp index adc1f01044..b8004c66b6 100644 --- a/examples/s4u/platform-failures/s4u-platform-failures.cpp +++ b/examples/s4u/platform-failures/s4u-platform-failures.cpp @@ -44,11 +44,9 @@ static int master(int argc, char* argv[]) } catch (const simgrid::TimeoutError&) { delete payload; XBT_INFO("Mmh. Got timeouted while speaking to '%s'. Nevermind. Let's keep going!", mailbox->get_cname()); - } catch (xbt_ex& e) { - if (e.category != network_error) - xbt_die("Unexpected behavior"); - XBT_INFO("Mmh. The communication with '%s' failed. Nevermind. Let's keep going!", mailbox->get_cname()); + } catch (const simgrid::NetworkFailureException&) { delete payload; + XBT_INFO("Mmh. The communication with '%s' failed. Nevermind. Let's keep going!", mailbox->get_cname()); } } @@ -62,10 +60,8 @@ static int master(int argc, char* argv[]) } catch (const simgrid::TimeoutError&) { delete payload; XBT_INFO("Mmh. Got timeouted while speaking to '%s'. Nevermind. Let's keep going!", mailbox->get_cname()); - } catch (xbt_ex& e) { + } catch (const simgrid::NetworkFailureException&) { delete payload; - if (e.category != network_error) - xbt_die("Unexpected behavior"); XBT_INFO("Mmh. Something went wrong with '%s'. Nevermind. Let's keep going!", mailbox->get_cname()); } } @@ -96,9 +92,7 @@ static int worker(int argc, char* argv[]) XBT_INFO("Start execution..."); simgrid::s4u::this_actor::execute(comp_size); XBT_INFO("Execution complete."); - } catch (xbt_ex& e) { - if (e.category != network_error) - xbt_die("Unexpected behavior. Category: %s", xbt_ex_catname(e.category)); + } catch (const simgrid::NetworkFailureException&) { XBT_INFO("Mmh. Something went wrong. Nevermind. Let's keep going!"); } } diff --git a/src/msg/msg_comm.cpp b/src/msg/msg_comm.cpp index d9bdac3f36..fcd867ca08 100644 --- a/src/msg/msg_comm.cpp +++ b/src/msg/msg_comm.cpp @@ -34,13 +34,9 @@ bool Comm::test() } catch (const simgrid::CancelException&) { status_ = MSG_TASK_CANCELED; finished = true; - } catch (xbt_ex& e) { - if (e.category == network_error) { - status_ = MSG_TRANSFER_FAILURE; - finished = true; - } else { - throw; - } + } catch (const simgrid::NetworkFailureException&) { + status_ = MSG_TRANSFER_FAILURE; + finished = true; } return finished; @@ -60,11 +56,8 @@ msg_error_t Comm::wait_for(double timeout) status_ = MSG_TIMEOUT; } catch (const simgrid::CancelException&) { status_ = MSG_TASK_CANCELED; - } catch (xbt_ex& e) { - if (e.category == network_error) - status_ = MSG_TRANSFER_FAILURE; - else - throw; + } catch (const simgrid::NetworkFailureException&) { + status_ = MSG_TRANSFER_FAILURE; } return status_; @@ -107,15 +100,13 @@ int MSG_comm_testany(xbt_dynar_t comms) msg_error_t status = MSG_OK; try { finished_index = simcall_comm_testany(s_comms.data(), s_comms.size()); - } catch (simgrid::TimeoutError& e) { + } catch (const simgrid::TimeoutError& e) { finished_index = e.value; status = MSG_TIMEOUT; - } catch (simgrid::CancelException& e) { + } catch (const simgrid::CancelException& e) { finished_index = e.value; status = MSG_TASK_CANCELED; - } catch (xbt_ex& e) { - if (e.category != network_error) - throw; + } catch (const simgrid::NetworkFailureException& e) { finished_index = e.value; status = MSG_TRANSFER_FAILURE; } @@ -186,19 +177,15 @@ int MSG_comm_waitany(xbt_dynar_t comms) msg_error_t status = MSG_OK; try { finished_index = simcall_comm_waitany(s_comms.data(), s_comms.size(), -1); - } catch (simgrid::TimeoutError& e) { + } catch (const simgrid::TimeoutError& e) { finished_index = e.value; status = MSG_TIMEOUT; - } catch (simgrid::CancelException& e) { + } catch (const simgrid::CancelException& e) { finished_index = e.value; status = MSG_TASK_CANCELED; - } catch (xbt_ex& e) { - if (e.category == network_error) { - finished_index = e.value; - status = MSG_TRANSFER_FAILURE; - } else { - throw; - } + } catch (const simgrid::NetworkFailureException& e) { + finished_index = e.value; + status = MSG_TRANSFER_FAILURE; } xbt_assert(finished_index != -1, "WaitAny returned -1"); diff --git a/src/msg/msg_task.cpp b/src/msg/msg_task.cpp index 9094468620..7284a20a48 100644 --- a/src/msg/msg_task.cpp +++ b/src/msg/msg_task.cpp @@ -137,12 +137,8 @@ msg_error_t Task::send(const std::string& alias, double timeout) ret = MSG_TIMEOUT; } catch (const simgrid::CancelException&) { ret = MSG_HOST_FAILURE; - } catch (xbt_ex& e) { - if (e.category == network_error) - ret = MSG_TRANSFER_FAILURE; - else - throw; - + } catch (const simgrid::NetworkFailureException&) { + ret = MSG_TRANSFER_FAILURE; /* If the send failed, it is not used anymore */ set_not_used(); } @@ -631,11 +627,8 @@ msg_error_t MSG_task_receive_ext_bounded(msg_task_t* task, const char* alias, do ret = MSG_TIMEOUT; } catch (const simgrid::CancelException&) { ret = MSG_TASK_CANCELED; - } catch (xbt_ex& e) { - if (e.category == network_error) - ret = MSG_TRANSFER_FAILURE; - else - throw; + } catch (const simgrid::NetworkFailureException&) { + ret = MSG_TRANSFER_FAILURE; } if (TRACE_actor_is_enabled() && ret != MSG_HOST_FAILURE && ret != MSG_TRANSFER_FAILURE && ret != MSG_TIMEOUT) { -- 2.20.1