-
Notifications
You must be signed in to change notification settings - Fork 73
grpc-labview ought to make better use of C++ exceptions #437
Copy link
Copy link
Open
Description
The grpc-labview C++ codebase has a lot of duplicated error handling, and #436 adds more.
Instead of duplicating checks for failed casts, etc. in each exported function, the checks could be single-sourced:
- Create a C++ exception class for an exception with an error code.
- Change
CastToto throw an exception with the appropriate error code when it fails - Add a
TryCastTomethod for use cases that require casting to null, and update callers to use it when appropriate. - Add an exception dispatcher method like
int32_t translateException() { try { throw; } catch (const MyExceptionWithErrorCode& e) { return e.code; } catch (const std::exception& e) { logException(e); return SOME_ERROR_CODE; } }
- Add a try/catch block to each exported function that uses the exception dispatcher:
It is possible to wrap this in a macro, but not necessary, since most of the logic is single sourced in the exception dispatcher function.
try { ... } catch (const std::exception&) { return translateException(); }
The code already does some of this, but only for invalid enum values.
Originally posted by @bkeryan in #436 (comment)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels