8000 grpc-labview ought to make better use of C++ exceptions · Issue #437 · ni/grpc-labview · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

grpc-labview ought to make better use of C++ exceptions 8000 #437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
bkeryan opened this issue May 6, 2025 · 1 comment
Open

grpc-labview ought to make better use of C++ exceptions #437

bkeryan opened this issue May 6, 2025 · 1 comment

Comments

@bkeryan
Copy link
Collaborator
bkeryan commented May 6, 2025

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 CastTo to throw an exception with the appropriate error code when it fails
  • Add a TryCastTo method 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:
    try {
        ...
    } catch (const std::exception&) {
        return translateException();
    }
    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.

The code already does some of this, but only for invalid enum values.

Originally posted by @bkeryan in #436 (comment)

AB#3117529

@bkeryan bkeryan changed the title grpc-labview ought to make better use of C++ exceptions. Instead of duplicating these checks in each exported function, the checks could be single-sourced: grpc-labview ought to make better use of C++ exceptions May 6, 2025
@bkeryan
Copy link
Collaborator Author
bkeryan commented May 15, 2025

The feature toggle code would also benefit from being able to use C++ exceptions to report errors. Currently it ignores errors from
opening std::ifstream, GetModuleHandle, etc. It makes sense to ignore file-not-found when using the default feature toggle file path, but other errors ought to be reported to the caller.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0