: std::runtime_error(std::move(message)), throwpoint_(std::move(throwpoint))
{
}
+ ~Exception(); // DO NOT define it here -- see Exception.cpp for a rationale
/** Return the information about where the exception was thrown */
xbt::ThrowPoint const& throw_point() const { return throwpoint_; }
std::string const resolve_backtrace() const { return throwpoint_.backtrace_.resolve(); }
+ /** Allow to carry a value (used by waitall/waitany) */
+ int value = 0;
+
private:
xbt::ThrowPoint throwpoint_;
};
-} // namespace simgrid
-
-/** A legacy exception
- *
- * It is defined by a category and a value within that category (as well as
- * an optional error message).
- *
- * This used to be a structure for C exceptions but it has been retrofitted
- * as a C++ exception and some of its data has been moved in the
- * @ref WithContextException base class. We should deprecate it and replace it
- * with either C++ different exceptions or `std::system_error` which already
- * provides this (category + error code) logic.
- * TODO ^^
- *
- * @ingroup XBT_ex_c
- */
-class XBT_PUBLIC xbt_ex : public simgrid::Exception {
-public:
- /**
- *
- * @param throwpoint Throw point (use XBT_THROW_POINT)
- * @param message Exception message
- */
- xbt_ex(simgrid::xbt::ThrowPoint&& throwpoint, std::string&& message)
- : simgrid::Exception(std::move(throwpoint), std::move(message))
- {
- }
-
- xbt_ex(const xbt_ex&) = default;
-
- ~xbt_ex(); // DO NOT define it here -- see ex.cpp for a rationale
-
- /** Category (what went wrong) */
- xbt_errcat_t category = unknown_error;
-
- /** Why did it went wrong */
- int value = 0;
-};
-
-namespace simgrid {
-
/** Exception raised when a timeout elapsed */
-class TimeoutError : public xbt_ex {
+class TimeoutError : public Exception {
public:
TimeoutError(simgrid::xbt::ThrowPoint&& throwpoint, std::string&& message)
- : xbt_ex(std::move(throwpoint), std::move(message))
+ : Exception(std::move(throwpoint), std::move(message))
{
- category = timeout_error;
}
};
/** Exception raised when a host fails */
-class HostFailureException : public xbt_ex {
+class HostFailureException : public Exception {
public:
HostFailureException(simgrid::xbt::ThrowPoint&& throwpoint, std::string&& message)
- : xbt_ex(std::move(throwpoint), std::move(message))
+ : Exception(std::move(throwpoint), std::move(message))
{
- category = host_error;
}
};
/** Exception raised when a communication fails because of the network or because of the remote host */
-class NetworkFailureException : public xbt_ex {
+class NetworkFailureException : public Exception {
public:
NetworkFailureException(simgrid::xbt::ThrowPoint&& throwpoint, std::string&& message)
- : xbt_ex(std::move(throwpoint), std::move(message))
+ : Exception(std::move(throwpoint), std::move(message))
{
- category = network_error;
}
};
/** Exception raised when a storage fails */
-class StorageFailureException : public xbt_ex {
+class StorageFailureException : public Exception {
public:
StorageFailureException(simgrid::xbt::ThrowPoint&& throwpoint, std::string&& message)
- : xbt_ex(std::move(throwpoint), std::move(message))
+ : Exception(std::move(throwpoint), std::move(message))
{
- category = io_error;
}
};
/** Exception raised when a VM fails */
-class VmFailureException : public xbt_ex {
+class VmFailureException : public Exception {
public:
VmFailureException(simgrid::xbt::ThrowPoint&& throwpoint, std::string&& message)
- : xbt_ex(std::move(throwpoint), std::move(message))
+ : Exception(std::move(throwpoint), std::move(message))
{
- category = vm_error;
}
};
/** Exception raised when something got canceled before completion */
-class CancelException : public xbt_ex {
+class CancelException : public Exception {
public:
CancelException(simgrid::xbt::ThrowPoint&& throwpoint, std::string&& message)
- : xbt_ex(std::move(throwpoint), std::move(message))
+ : Exception(std::move(throwpoint), std::move(message))
{
- category = cancel_error;
}
};
/** Exception raised when something is going wrong during the simulation tracing */
-class TracingError : public xbt_ex {
+class TracingError : public Exception {
public:
TracingError(simgrid::xbt::ThrowPoint&& throwpoint, std::string&& message)
- : xbt_ex(std::move(throwpoint), std::move(message))
+ : Exception(std::move(throwpoint), std::move(message))
{
- category = tracing_error;
}
};
} // namespace simgrid
+XBT_ATTRIB_DEPRECATED_v327("Please use simgrid::Exception") typedef simgrid::Exception xbt_ex;
+
#endif
* exactly play nicely together.
*/
-/** Categories of errors
- *
- * This very similar to std::error_catgory and should probably be replaced
- * by this in the future.
- *
- * @ingroup XBT_ex_c
- */
-typedef enum {
- unknown_error = 0, /**< unknown error */
- arg_error, /**< Invalid argument */
- bound_error, /**< Out of bounds argument */
- mismatch_error, /**< The provided ID does not match */
- not_found_error, /**< The searched element was not found */
- system_error, /**< a syscall did fail */
- network_error, /**< error while sending/receiving data */
- timeout_error, /**< not quick enough, dude */
- cancel_error, /**< an action was canceled */
- thread_error, /**< error while [un]locking */
- host_error, /**< host failed */
- tracing_error, /**< error during the simulation tracing */
- io_error, /**< disk or file error */
- vm_error /**< vm error */
-} xbt_errcat_t;
-
SG_BEGIN_DECL()
-/** Get the name of a category
- * @ingroup XBT_ex_c
- */
-XBT_PUBLIC const char* xbt_ex_catname(xbt_errcat_t cat);
-
/** Helper function used to throw exceptions in C */
-XBT_ATTRIB_NORETURN XBT_PUBLIC void _xbt_throw(char* message, xbt_errcat_t errcat, int value, const char* file,
- int line, const char* func);
+XBT_ATTRIB_NORETURN XBT_PUBLIC void _xbt_throw(char* message, int value, const char* file, int line, const char* func);
/** Builds and throws an exception
* @ingroup XBT_ex_c
* @hideinitializer
*/
-#define THROW(c, v) { _xbt_throw(NULL, (xbt_errcat_t) c, v, __FILE__, __LINE__, __func__); }
+#define THROW(v) _xbt_throw(NULL, v, __FILE__, __LINE__, __func__)
/** Builds and throws an exception with a printf-like formatted message
* @ingroup XBT_ex_c
* @hideinitializer
*/
-#define THROWF(c, v, ...) _xbt_throw(bprintf(__VA_ARGS__), (xbt_errcat_t) c, v, __FILE__, __LINE__, __func__)
+#define THROWF(v, ...) _xbt_throw(bprintf(__VA_ARGS__), v, __FILE__, __LINE__, __func__)
XBT_ATTRIB_NORETURN void xbt_throw_impossible(const char* file, int line, const char* func);
/** Throw an exception because something impossible happened
// In order to modify the exception we have to rethrow it:
try {
std::rethrow_exception(simcall->issuer->exception_);
- } catch (simgrid::TimeoutError& e) {
- e.value = rank;
- simcall->issuer->exception_ = std::make_exception_ptr(e);
- } catch (simgrid::NetworkFailureException& e) {
- e.value = rank;
- simcall->issuer->exception_ = std::make_exception_ptr(e);
- } catch (simgrid::CancelException& e) {
+ } catch (simgrid::Exception& e) {
e.value = rank;
simcall->issuer->exception_ = std::make_exception_ptr(e);
}
comm = mbox->put_init(msg, size)->set_rate(mig_speed)->wait_for(timeout);
else
comm = mbox->put_async(msg, size)->wait_for(timeout);
- } catch (const xbt_ex&) {
+ } catch (const Exception&) {
if (comm) {
sg_size_t remaining = static_cast<sg_size_t>(comm->get_remaining());
XBT_VERB("timeout (%lf s) in sending_migration_data, remaining %llu bytes of %llu", timeout, remaining, size);
} else if (sent > ramsize)
XBT_CRITICAL("bug");
- } catch (const xbt_ex&) {
+ } catch (const Exception&) {
// hostfailure (if you want to know whether this is the SRC or the DST check directly in send_migration_data code)
// Stop the dirty page tracking an return (there is no memory space to release)
sg_vm_stop_dirty_page_tracking(vm_);
try {
XBT_DEBUG("Stage 2, gonna send %llu", updated_size);
sent = sendMigrationData(updated_size, 2, stage2_round, mig_speed, mig_timeout);
- } catch (const xbt_ex&) {
+ } catch (const Exception&) {
// hostfailure (if you want to know whether this is the SRC or the DST check directly in send_migration_data
// code)
// Stop the dirty page tracking an return (there is no memory space to release)
try {
XBT_DEBUG("Stage 3: Gonna send %zu bytes", remaining_size);
sendMigrationData(remaining_size, 3, 0, mig_speed, -1);
- } catch (const xbt_ex&) {
+ } catch (const Exception&) {
// hostfailure (if you want to know whether this is the SRC or the DST check directly in send_migration_data code)
// Stop the dirty page tracking an return (there is no memory space to release)
vm_->resume();
double start = xbt_os_time();
try {
parse_platform_file(platf);
- } catch (xbt_ex& e) {
+ } catch (const Exception& e) {
xbt_die("Error while loading %s: %s", platf.c_str(), e.what());
}
namespace simgrid {
+// DO NOT define destructors for exceptions in Exception.hpp.
+// Defining it here ensures that the exceptions are defined only in libsimgrid, but not in libsimgrid-java.
+// Doing otherwise naturally breaks things (at least on freebsd with clang).
+
+Exception::~Exception() = default;
ForcefulKillException::~ForcefulKillException() = default;
void ForcefulKillException::do_throw()
parse_status = surf_parse();
surf_parse_close();
xbt_assert(not parse_status, "Parse error at %s:%d", file.c_str(), surf_parse_lineno);
- } catch (const xbt_ex&) {
+ } catch (const simgrid::Exception&) {
XBT_ERROR(
"Unrecoverable error at %s:%d. The full exception stack follows, in case it helps you to diagnose the problem.",
file.c_str(), surf_parse_lineno);
if ((*request)->action_ != nullptr){
try{
*flag = simcall_comm_test((*request)->action_);
- } catch (const xbt_ex&) {
+ } catch (const Exception&) {
*flag = 0;
return ret;
}
simcall_process_sleep(nsleeps*smpi_test_sleep);
try{
i = simcall_comm_testany(comms.data(), comms.size()); // The i-th element in comms matches!
- } catch (const xbt_ex&) {
+ } catch (const Exception&) {
XBT_DEBUG("Exception in testany");
return 0;
}
try{
// this is not a detached send
simcall_comm_wait((*request)->action_, -1.0);
- } catch (const xbt_ex&) {
+ } catch (const Exception&) {
XBT_VERB("Request cancelled");
}
}
try{
// this is not a detached send
i = simcall_comm_waitany(comms.data(), comms.size(), -1);
- } catch (const xbt_ex&) {
+ } catch (const Exception&) {
XBT_INFO("request %d cancelled ", i);
return i;
}
XBT_LOG_EXTERNAL_CATEGORY(xbt);
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_exception, xbt, "Exceptions");
-// DO NOT define ~xbt_ex() in exception.hpp.
-// Defining it here ensures that xbt_ex is defined only in libsimgrid, but not in libsimgrid-java.
-// Doing otherwise naturally breaks things (at least on freebsd with clang).
-
-xbt_ex::~xbt_ex() = default;
-
-void _xbt_throw(char* message, xbt_errcat_t errcat, int value, const char* file, int line, const char* func)
+void _xbt_throw(char* message, int value, const char* file, int line, const char* func)
{
- xbt_ex e(simgrid::xbt::ThrowPoint(file, line, func, simgrid::xbt::Backtrace(), xbt_procname(), xbt_getpid()),
- message);
+ simgrid::Exception e(
+ simgrid::xbt::ThrowPoint(file, line, func, simgrid::xbt::Backtrace(), xbt_procname(), xbt_getpid()),
+ message ? message : "");
xbt_free(message);
- e.category = errcat;
e.value = value;
throw e;
}
-/** @brief returns a short name for the given exception category */
-const char* xbt_ex_catname(xbt_errcat_t cat)
-{
- switch (cat) {
- case unknown_error:
- return "unknown error";
- case arg_error:
- return "invalid argument";
- case bound_error:
- return "out of bounds";
- case mismatch_error:
- return "mismatch";
- case not_found_error:
- return "not found";
- case system_error:
- return "system error";
- case network_error:
- return "network error";
- case timeout_error:
- return "timeout";
- case cancel_error:
- return "action canceled";
- case thread_error:
- return "thread error";
- case host_error:
- return "host failed";
- case tracing_error:
- return "tracing error";
- case io_error:
- return "io error";
- case vm_error:
- return "vm error";
- default:
- return "INVALID ERROR";
- }
-}
-
namespace simgrid {
namespace xbt {
switch (type) {
case MMALLOC_TYPE_HEAPINFO:
UNLOCK(mdp);
- THROWF(system_error, 0, "Asked to free a fragment in a heapinfo block. I'm confused.\n");
+ THROWF(0, "Asked to free a fragment in a heapinfo block. I'm confused.\n");
break;
case MMALLOC_TYPE_FREE: /* Already free */
UNLOCK(mdp);
- THROWF(system_error, 0, "Asked to free a fragment in a block that is already free. I'm puzzled.\n");
+ THROWF(0, "Asked to free a fragment in a block that is already free. I'm puzzled.\n");
break;
case MMALLOC_TYPE_UNFRAGMENTED:
if( mdp->heapinfo[block].busy_frag.frag_size[frag_nb] == -1){
UNLOCK(mdp);
- THROWF(system_error, 0, "Asked to free a fragment that is already free. I'm puzzled\n");
+ THROWF(0, "Asked to free a fragment that is already free. I'm puzzled\n");
}
if (MC_is_active() && mdp->heapinfo[block].busy_frag.ignore[frag_nb] > 0)
action_fun function = action_funs.at(action.at(1));
try {
function(action);
- } catch (xbt_ex& e) {
+ } catch (const Exception& e) {
action.clear();
xbt_die("Replay error:\n %s", e.what());
}
mfree(heapA, pointers[i]);
try {
mfree(heapA, pointers[i]);
- } catch (const xbt_ex&) {
+ } catch (const simgrid::Exception&) {
gotit = true;
}
if (not gotit)
bool gotit = false;
try {
mfree(heapA, pointers[i]);
- } catch (const xbt_ex&) {
+ } catch (const simgrid::Exception&) {
gotit = true;
}
if (not gotit)