Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
sanitize the OOP of kernel::profile
[simgrid.git] / src / bindings / java / jmsg_process.cpp
index 3e1faae..fc495a5 100644 (file)
@@ -225,9 +225,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_sleep(JNIEnv *env, jclass cl
  {
   double time =  ((double)jmillis) / 1000 + ((double)jnanos) / 1000000000;
   msg_error_t rv;
-  try {
-    rv = MSG_process_sleep(time);
-  } catch (simgrid::kernel::context::Context::StopRequest const&) {
+  if (not simgrid::kernel::context::StopRequest::try_n_catch([&rv, &time]() { rv = MSG_process_sleep(time); })) {
     rv = MSG_HOST_FAILURE;
   }
   if (rv != MSG_OK) {
@@ -240,7 +238,10 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_sleep(JNIEnv *env, jclass cl
 JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_waitFor(JNIEnv * env, jobject jprocess, jdouble jseconds)
 {
   msg_error_t rv;
-  rv = MSG_process_sleep((double)jseconds);
+  if (not simgrid::kernel::context::StopRequest::try_n_catch(
+          [&rv, &jseconds]() { rv = MSG_process_sleep((double)jseconds); })) {
+    jxbt_throw_by_name(env, "org/simgrid/msg/ProcessKilledError", "Process killed");
+  }
   if (env->ExceptionOccurred())
     return;
   if (rv != MSG_OK) {
@@ -257,12 +258,8 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_kill(JNIEnv * env, jobject j
     jxbt_throw_notbound(env, "process", jprocess);
     return;
   }
-  try {
-    MSG_process_kill(process);
-  } catch (xbt_ex& ex) {
-    XBT_VERB("Process %s just committed a suicide", MSG_process_get_name(process));
-    xbt_assert(process == MSG_process_self(),
-               "Killing a process should not raise an exception if it's not a suicide. Please report that bug.");
+  if (not simgrid::kernel::context::StopRequest::try_n_catch([&process]() { MSG_process_kill(process); })) {
+    jxbt_throw_by_name(env, "org/simgrid/msg/ProcessKilledError", "Process killed");
   }
 }