vendredi 28 août 2020

Rethrow custom exceptions in several methods C++11

I have a use case where I have to catch various exception that can be thrown and pass an equivalent exception from my library

example:

def subscribe() {
    try {
       .....
       .....
    catch (A e) { throw new MY_A(e);}
    catch (B e) { throw new MY_B(e);}
    catch (C e) { throw new MY_C(e);}
    catch(...) { throw default(e)}
}

I wanted to do this for several methods - subscribe, unsubscribe, stop, start etc., Is there any easy way of doing this ?

Had it been in python, I would have simply written a decorator and achieved this. What will be the easy way to do this in C++11 ?

Aucun commentaire:

Enregistrer un commentaire