ecorm / cppwamp

C++ client library for the WAMP protocol.
Boost Software License 1.0
35 stars 9 forks source link

Provide exception base class for easy mapping to ERROR messages #76

Closed ecorm closed 8 years ago

ecorm commented 9 years ago

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 8 years ago

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.