mardi 14 septembre 2021

Lightweight modern design for error handling in c++

I use a library in my project who's API return a Status to indicate successes/errors with different types Status. For example:

struct StatusOk : Status {};
struct StatusBadMovement : Status {};

The list of those types is pretty long, and for each error, the application (client) should process and handle the error differently. The first implementation would be to have an endless if/else list testing each type and calling the appropriate handler.

Is there another more modern way to subscribe to said signals and execute handles when errors occur, in a centralized and unithreaded way?

I saw the MError library from google that generates such signals (https://github.com/google/merror) but there's no indication on what's the best way to handle those statuses with a proper design where performance is critical.

Thanks

Aucun commentaire:

Enregistrer un commentaire