Commit 5ac2c932 authored by Dominik Charousset's avatar Dominik Charousset

Fix build with CAF_NO_EXCEPTIONS enabled

parent f67e6a11
......@@ -19,6 +19,7 @@
#include "caf/scheduled_actor.hpp"
#include "caf/config.hpp"
#include "caf/actor_ostream.hpp"
#include "caf/detail/private_thread.hpp"
......@@ -481,9 +482,9 @@ bool scheduled_actor::activate(execution_unit* ctx) {
"resume called on a terminated actor");
return false;
}
# ifndef CAF_NO_EXCEPTION
# ifndef CAF_NO_EXCEPTIONS
try {
# endif // CAF_NO_EXCEPTION
# endif // CAF_NO_EXCEPTIONS
if (! is_initialized()) {
initialize();
if (finalize()) {
......@@ -493,7 +494,7 @@ bool scheduled_actor::activate(execution_unit* ctx) {
CAF_LOG_DEBUG("initialized actor:" << CAF_ARG(name()));
}
}
# ifndef CAF_NO_EXCEPTION
# ifndef CAF_NO_EXCEPTIONS
}
catch (...) {
CAF_LOG_ERROR("actor died during initialization");
......@@ -502,7 +503,7 @@ bool scheduled_actor::activate(execution_unit* ctx) {
finalize();
return false;
}
# endif // CAF_NO_EXCEPTION
# endif // CAF_NO_EXCEPTIONS
return true;
}
......@@ -516,9 +517,9 @@ 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_EXCEPTION
# ifndef CAF_NO_EXCEPTIONS
try {
# endif // CAF_NO_EXCEPTION
# endif // CAF_NO_EXCEPTIONS
switch (consume(x)) {
case im_dropped:
return activation_result::dropped;
......@@ -532,7 +533,7 @@ auto scheduled_actor::reactivate(mailbox_element& x) -> activation_result {
case im_skipped:
return activation_result::skipped;
}
# ifndef CAF_NO_EXCEPTION
# ifndef CAF_NO_EXCEPTIONS
}
catch (std::exception& e) {
CAF_LOG_INFO("actor died because of an exception, what: " << e.what());
......@@ -547,7 +548,7 @@ auto scheduled_actor::reactivate(mailbox_element& x) -> activation_result {
}
finalize();
return activation_result::terminated;
# endif // CAF_NO_EXCEPTION
# endif // CAF_NO_EXCEPTIONS
}
// -- behavior management ----------------------------------------------------
......
......@@ -26,6 +26,8 @@
using namespace caf;
#ifndef CAF_NO_EXCEPTIONS
class exception_testee : public event_based_actor {
public:
~exception_testee();
......@@ -77,3 +79,11 @@ 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
......@@ -559,66 +559,6 @@ CAF_TEST(constructor_attach) {
anon_send_exit(system.spawn<spawner>(), exit_reason::user_shutdown);
}
namespace {
class exception_testee : public event_based_actor {
public:
exception_testee(actor_config& cfg) : event_based_actor(cfg) {
set_exception_handler([](std::exception_ptr&) -> exit_reason {
return exit_reason::unhandled_exception;
});
}
behavior make_behavior() override {
return {
[](const std::string& str) {
throw std::runtime_error(str);
}
};
}
};
} // namespace <anonymous>
CAF_TEST(custom_exception_handler) {
auto handler = [](std::exception_ptr& eptr) -> error {
try {
std::rethrow_exception(eptr);
}
catch (std::runtime_error&) {
return exit_reason::unhandled_exception;
}
catch (...) {
// "fall through"
}
return exit_reason::unknown;
};
scoped_actor self{system};
auto testee1 = self->spawn<monitored>([=](event_based_actor* eb_self) {
eb_self->set_exception_handler(handler);
throw std::runtime_error("ping");
});
auto testee2 = self->spawn<monitored>([=](event_based_actor* eb_self) {
eb_self->set_exception_handler(handler);
throw std::logic_error("pong");
});
auto testee3 = self->spawn<exception_testee, monitored>();
self->send(testee3, "foo");
// receive all down messages
int downs_received = 0;
self->receive_for(downs_received, 3) (
[&](down_msg& dm) {
if (dm.source == testee1)
CAF_CHECK_EQUAL(dm.reason, exit_reason::unhandled_exception);
else if (dm.source == testee2)
CAF_CHECK_EQUAL(dm.reason, exit_reason::unknown);
else if (dm.source == testee3)
CAF_CHECK_EQUAL(dm.reason, exit_reason::unhandled_exception);
else
throw std::runtime_error("received message from unexpected source");
}
);
}
CAF_TEST(kill_the_immortal) {
auto wannabe_immortal = system.spawn([](event_based_actor* self) -> behavior {
self->set_exit_handler([](local_actor*, exit_msg&) {
......
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