jeudi 21 février 2019

class for handling custom exception

I would like to create a class which takes std::function and allow to handle specified exceptions but I'm not sure if it is possible.

Here is some pseudo draft:

//exception types
template<class... Args>
class CustomExceptionHandler
{
public:
    CustomExceptionHandler(std::function<void()> clb): clb_(std::move(clb)){}

    void ExecuteCallback()
    {
        try
        {
            clb_();
        }
        /*catch specified exception types*/
    }

private:
    std::function<void()> clb_;
};

//usage
CustomExceptionHandler<std::out_of_range, std::overflow_error> handler(clb);
handler.ExecuteCallback();

I don't know how to use a variadic template to grab exception types and use it later. Is it possible ?

Aucun commentaire:

Enregistrer un commentaire