Commit 483fcc4c authored by Dominik Charousset's avatar Dominik Charousset

Switch to new CAF_ENABLE_EXCEPTIONS flag

parent 244475ea
......@@ -25,10 +25,8 @@
#define CAF_LOG_LEVEL CAF_LOG_LEVEL_@CAF_LOG_LEVEL@
#cmakedefine CAF_NO_MEM_MANAGEMENT
#cmakedefine CAF_ENABLE_RUNTIME_CHECKS
#cmakedefine CAF_NO_EXCEPTIONS
#cmakedefine CAF_ENABLE_EXCEPTIONS
#cmakedefine CAF_ENABLE_ACTOR_PROFILER
......@@ -20,7 +20,7 @@
#include "caf/config.hpp"
#ifndef CAF_NO_EXCEPTIONS
#ifdef CAF_ENABLE_EXCEPTIONS
# include <stdexcept>
#endif
......@@ -33,32 +33,32 @@ CAF_CORE_EXPORT void log_cstring_error(const char* cstring);
} // namespace caf::detail
#ifdef CAF_NO_EXCEPTIONS
#ifdef CAF_ENABLE_EXCEPTIONS
# define CAF_RAISE_ERROR_IMPL_1(msg) \
# define CAF_RAISE_ERROR_IMPL_2(exception_type, msg) \
do { \
::caf::detail::log_cstring_error(msg); \
CAF_CRITICAL(msg); \
throw exception_type(msg); \
} while (false)
# define CAF_RAISE_ERROR_IMPL_2(unused, msg) CAF_RAISE_ERROR_IMPL_1(msg)
# define CAF_RAISE_ERROR_IMPL_1(msg) \
CAF_RAISE_ERROR_IMPL_2(std::runtime_error, msg)
#else // CAF_NO_EXCEPTIONS
#else // CAF_ENABLE_EXCEPTIONS
# define CAF_RAISE_ERROR_IMPL_2(exception_type, msg) \
# define CAF_RAISE_ERROR_IMPL_1(msg) \
do { \
::caf::detail::log_cstring_error(msg); \
throw exception_type(msg); \
CAF_CRITICAL(msg); \
} while (false)
# define CAF_RAISE_ERROR_IMPL_1(msg) \
CAF_RAISE_ERROR_IMPL_2(std::runtime_error, msg)
# define CAF_RAISE_ERROR_IMPL_2(unused, msg) CAF_RAISE_ERROR_IMPL_1(msg)
#endif // CAF_NO_EXCEPTIONS
#endif // CAF_ENABLE_EXCEPTIONS
#ifdef CAF_MSVC
/// Throws an exception if `CAF_NO_EXCEPTIONS` is undefined, otherwise calls
/// Throws an exception if `CAF_ENABLE_EXCEPTIONS` is defined, otherwise calls
/// abort() after printing a given message.
# define CAF_RAISE_ERROR(...) \
CAF_PP_CAT(CAF_PP_OVERLOAD(CAF_RAISE_ERROR_IMPL_, \
......@@ -67,7 +67,7 @@ CAF_CORE_EXPORT void log_cstring_error(const char* cstring);
#else // CAF_MSVC
/// Throws an exception if `CAF_NO_EXCEPTIONS` is undefined, otherwise calls
/// Throws an exception if `CAF_ENABLE_EXCEPTIONS` is defined, otherwise calls
/// abort() after printing a given message.
# define CAF_RAISE_ERROR(...) \
CAF_PP_OVERLOAD(CAF_RAISE_ERROR_IMPL_, __VA_ARGS__)(__VA_ARGS__)
......
......@@ -20,9 +20,9 @@
#include "caf/config.hpp"
#ifndef CAF_NO_EXCEPTIONS
#ifdef CAF_ENABLE_EXCEPTIONS
# include <exception>
#endif // CAF_NO_EXCEPTIONS
#endif // CAF_ENABLE_EXCEPTIONS
#include <forward_list>
#include <map>
......@@ -190,10 +190,10 @@ public:
/// Function object for handling exit messages.
using exit_handler = std::function<void(pointer, exit_msg&)>;
#ifndef CAF_NO_EXCEPTIONS
#ifdef CAF_ENABLE_EXCEPTIONS
/// Function object for handling exit messages.
using exception_handler = std::function<error(pointer, std::exception_ptr&)>;
#endif // CAF_NO_EXCEPTIONS
#endif // CAF_ENABLE_EXCEPTIONS
/// Consumes messages from the mailbox.
struct mailbox_visitor {
......@@ -232,9 +232,9 @@ public:
static void default_exit_handler(pointer ptr, exit_msg& x);
#ifndef CAF_NO_EXCEPTIONS
#ifdef CAF_ENABLE_EXCEPTIONS
static error default_exception_handler(pointer ptr, std::exception_ptr& x);
#endif // CAF_NO_EXCEPTIONS
#endif // CAF_ENABLE_EXCEPTIONS
// -- constructors and destructors -------------------------------------------
......@@ -389,7 +389,7 @@ public:
set_exit_handler([fun](scheduled_actor*, exit_msg& x) { fun(x); });
}
#ifndef CAF_NO_EXCEPTIONS
#ifdef CAF_ENABLE_EXCEPTIONS
/// Sets a custom exception handler for this actor. If multiple handlers are
/// defined, only the functor that was added *last* is being executed.
inline void set_exception_handler(exception_handler fun) {
......@@ -408,7 +408,7 @@ public:
set_exception_handler(
[f](scheduled_actor*, std::exception_ptr& x) { return f(x); });
}
#endif // CAF_NO_EXCEPTIONS
#endif // CAF_ENABLE_EXCEPTIONS
/// @cond PRIVATE
......@@ -703,10 +703,10 @@ protected:
/// Pointer to a private thread object associated with a detached actor.
detail::private_thread* private_thread_;
#ifndef CAF_NO_EXCEPTIONS
#ifdef CAF_ENABLE_EXCEPTIONS
/// Customization point for setting a default exception callback.
exception_handler exception_handler_;
#endif // CAF_NO_EXCEPTIONS
#endif // CAF_ENABLE_EXCEPTIONS
/// @endcond
};
......
......@@ -104,7 +104,7 @@ public:
self_->set_exit_handler(std::forward<Fun>(fun));
}
#ifndef CAF_NO_EXCEPTIONS
#ifdef CAF_ENABLE_EXCEPTIONS
/// @copydoc scheduled_actor::set_exception_handler
template <class Fun>
......@@ -112,7 +112,7 @@ public:
self_->set_exception_handler(std::forward<Fun>(fun));
}
#endif // CAF_NO_EXCEPTIONS
#endif // CAF_ENABLE_EXCEPTIONS
// -- linking and monitoring -------------------------------------------------
......
......@@ -107,7 +107,7 @@ void blocking_actor::launch(execution_unit*, bool, bool hide) {
CAF_PUSH_AID_FROM_PTR(self);
self->initialize();
error rsn;
#ifndef CAF_NO_EXCEPTIONS
#ifdef CAF_ENABLE_EXCEPTIONS
try {
self->act();
rsn = self->fail_state_;
......
......@@ -97,7 +97,7 @@ void scheduled_actor::default_exit_handler(scheduled_actor* ptr, exit_msg& x) {
default_error_handler(ptr, x.reason);
}
#ifndef CAF_NO_EXCEPTIONS
#ifdef CAF_ENABLE_EXCEPTIONS
error scheduled_actor::default_exception_handler(pointer ptr,
std::exception_ptr& x) {
CAF_ASSERT(x != nullptr);
......@@ -115,7 +115,7 @@ error scheduled_actor::default_exception_handler(pointer ptr,
}
return sec::runtime_error;
}
#endif // CAF_NO_EXCEPTIONS
#endif // CAF_ENABLE_EXCEPTIONS
// -- constructors and destructors ---------------------------------------------
......@@ -129,10 +129,10 @@ scheduled_actor::scheduled_actor(actor_config& cfg)
node_down_handler_(default_node_down_handler),
exit_handler_(default_exit_handler),
private_thread_(nullptr)
#ifndef CAF_NO_EXCEPTIONS
#ifdef CAF_ENABLE_EXCEPTIONS
,
exception_handler_(default_exception_handler)
#endif // CAF_NO_EXCEPTIONS
#endif // CAF_ENABLE_EXCEPTIONS
{
auto& sys_cfg = home_system().config();
auto interval = sys_cfg.stream_tick_duration();
......@@ -743,9 +743,9 @@ bool scheduled_actor::activate(execution_unit* ctx) {
CAF_LOG_ERROR("activate called on a terminated actor");
return false;
}
#ifndef CAF_NO_EXCEPTIONS
#ifdef CAF_ENABLE_EXCEPTIONS
try {
#endif // CAF_NO_EXCEPTIONS
#endif // CAF_ENABLE_EXCEPTIONS
if (!getf(is_initialized_flag)) {
initialize();
if (finalize()) {
......@@ -754,7 +754,7 @@ bool scheduled_actor::activate(execution_unit* ctx) {
}
CAF_LOG_DEBUG("initialized actor:" << CAF_ARG(name()));
}
#ifndef CAF_NO_EXCEPTIONS
#ifdef CAF_ENABLE_EXCEPTIONS
} catch (...) {
CAF_LOG_ERROR("actor died during initialization");
auto eptr = std::current_exception();
......@@ -762,7 +762,7 @@ bool scheduled_actor::activate(execution_unit* ctx) {
finalize();
return false;
}
#endif // CAF_NO_EXCEPTIONS
#endif // CAF_ENABLE_EXCEPTIONS
return true;
}
......@@ -779,7 +779,7 @@ auto scheduled_actor::activate(execution_unit* ctx, mailbox_element& x)
auto scheduled_actor::reactivate(mailbox_element& x) -> activation_result {
CAF_LOG_TRACE(CAF_ARG(x));
#ifndef CAF_NO_EXCEPTIONS
#ifdef CAF_ENABLE_EXCEPTIONS
auto handle_exception = [&](std::exception_ptr eptr) {
auto err = call_handler(exception_handler_, this, eptr);
if (x.mid.is_request()) {
......@@ -789,7 +789,7 @@ auto scheduled_actor::reactivate(mailbox_element& x) -> activation_result {
quit(std::move(err));
};
try {
#endif // CAF_NO_EXCEPTIONS
#endif // CAF_ENABLE_EXCEPTIONS
switch (consume(x)) {
case invoke_message_result::dropped:
return activation_result::dropped;
......@@ -803,7 +803,7 @@ auto scheduled_actor::reactivate(mailbox_element& x) -> activation_result {
case invoke_message_result::skipped:
return activation_result::skipped;
}
#ifndef CAF_NO_EXCEPTIONS
#ifdef CAF_ENABLE_EXCEPTIONS
} catch (std::exception& e) {
CAF_LOG_INFO("actor died because of an exception, what: " << e.what());
static_cast<void>(e); // keep compiler happy when not logging
......@@ -814,7 +814,7 @@ auto scheduled_actor::reactivate(mailbox_element& x) -> activation_result {
}
finalize();
return activation_result::terminated;
#endif // CAF_NO_EXCEPTIONS
#endif // CAF_ENABLE_EXCEPTIONS
}
// -- behavior management ----------------------------------------------------
......
......@@ -24,7 +24,9 @@
using namespace caf;
#ifndef CAF_NO_EXCEPTIONS
#ifndef CAF_ENABLE_EXCEPTIONS
# error "building unit test for exception handlers in no-exceptions build"
#endif
class exception_testee : public event_based_actor {
public:
......@@ -77,11 +79,3 @@ CAF_TEST(test_custom_exception_handler) {
// receive all down messages
self->wait_for(testee1, testee2, testee3);
}
#else // CAF_NO_EXCEPTIONS
CAF_TEST(no_exceptions_dummy) {
CAF_CHECK_EQUAL(true, true);
}
#endif // CAF_NO_EXCEPTIONS
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment