SObjectizer  5.8
Loading...
Searching...
No Matches
so_5/exception_reaction/main.cpp
/*
* A sample for the exception reaction.
*/
#include <iostream>
#include <stdexcept>
// Main SObjectizer header file.
#include <so_5/all.hpp>
// A class of an agent which will throw an exception.
class a_hello_t final : public so_5::agent_t
{
public:
a_hello_t( context_t ctx ) : so_5::agent_t( ctx )
{}
void so_evt_start() override
{
throw std::runtime_error( "sample exception" );
}
{
}
};
int main()
{
try
{
env.register_agent_as_coop( env.make_agent< a_hello_t >() );
} );
}
catch( const std::exception & ex )
{
std::cerr << "Error: " << ex.what() << std::endl;
return 1;
}
return 0;
}
A helper header file for including all public SObjectizer stuff.
A base class for agents.
Definition agent.hpp:673
virtual exception_reaction_t so_exception_reaction() const noexcept
A reaction from SObjectizer to an exception from agent's event.
Definition agent.cpp:871
virtual void so_evt_start()
Hook on agent start inside SObjectizer.
Definition agent.cpp:832
SObjectizer Environment.
coop_handle_t register_agent_as_coop(std::unique_ptr< A > agent)
Register single agent as a cooperation.
std::unique_ptr< Agent > make_agent(Args &&... args)
Helper method for simplification of agents creation.
void launch(Init_Routine &&init_routine)
Launch a SObjectizer Environment with default parameters.
Definition api.hpp:142
exception_reaction_t
A reaction of SObjectizer to an exception from agent event.
Definition agent.hpp:65
@ shutdown_sobjectizer_on_exception
Definition agent.hpp:70