Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Catch specialized exceptions instead of generic xbt_ex.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 2 Jul 2019 13:47:05 +0000 (15:47 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 2 Jul 2019 14:12:21 +0000 (16:12 +0200)
doc/doxygen/uhood_switch.doc
examples/s4u/platform-failures/s4u-platform-failures.cpp
src/msg/msg_comm.cpp
src/msg/msg_task.cpp

index 123a25d..f9b3ad1 100644 (file)
@@ -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();
index adc1f01..b8004c6 100644 (file)
@@ -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!");
     }
   }
index d9bdac3..fcd867c 100644 (file)
@@ -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");
index 9094468..7284a20 100644 (file)
@@ -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) {