Provide exception base class for easy mapping to ERROR messages
ecorm opened this issue · 1 comments
ecorm commented
Provide an exception base class that allows for easy conversion to ERROR messages. For example:
namespace wamp
{
struct WithUri : public std::runtime_error
{
using std::runtime_error::runtime_error;
virtual std::string uri() const = 0;
};
} // namespace wamp
namespace myapp
{
struct BadMojo : public WithUri
{
using WithUri::WithUri;
virtual std::string uri() const override {return "myapp.error.bad_mojo";}
};
wamp::Outcome myRpc(wamp::Invocation inv)
{
if (bad mojo)
throw BadMojo("this be bad mojo, man");
else
...
}
} // namespace myapp
Whenever CppWAMP catches a WithUri
exception thrown from an RPC, it automatically returns an ERROR message with BadMojo::uri()
as the URI and with the what()
message as a payload argument.
ecorm commented
The library already processes wamp::Error
objects thrown from within with RPC handlers. wamp::Error
objects can be constructed with any custom reason URI. Users can already establish exception hierarchies under wamp::Error
if they wish. I'll be adding a virtual destructor to wamp::Error
for this purpose.
This feature will therefore not be implemented.