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

Switch to new CAF_ENABLE_EXCEPTIONS flag

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