Skip to content
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

Using noexcept to indicate which DART calls can throw exceptions. #878

Open
psigen opened this issue Apr 18, 2017 · 2 comments
Open

Using noexcept to indicate which DART calls can throw exceptions. #878

psigen opened this issue Apr 18, 2017 · 2 comments

Comments

@psigen
Copy link
Collaborator

psigen commented Apr 18, 2017

Discussion from #875:

@psigen: #875 (comment)

@mxgrey: Just a side question: Does DART already make use of noexcept to distinguish code paths that never throw exceptions from ones that do?

It seems like that could make it clearer to end-users which DART functions have this guarantee and which don't, since you are right that many loading/visualization/debugging functions don't need it and could have very nice std::exceptions instead.

I don't know what the pros/cons are here though, just curious.

@mxgrey: #875 (comment)

I agree that we should consider using noexcept for the benefit clarity and potential performance improvements. The catch (no pun intended) is that we do allow exceptions (in the form of assert) everywhere when DART is compiled in debug mode. The logic is that unwinding the stack is likely to be problematic when running a critical control loop, but it can be very useful when debugging errors.

Perhaps even more problematic is that applying the noexcept specifier to a function which calls any potentially-throwing functions will result in std::terminate if the noexcept function does not handle the exception itself. So if anything used inside of a DART noexcept function does throw an exception, then that DART function must handle the exception or else the entire program will be terminated.

I would like to be able to offer a guarantee to the user that DART functions will handle all possible internal exceptions in a reasonable way, but I think we would need to take some time to examine where all the potential exceptions could pop up inside of DART before we commit to applying the noexcept specifier anywhere.

Conclusion: I think if we have an opportunity to review the exception safety of DART in detail and can determine that using the noexcept specifier is safe, then we could use a macro which expands to noexcept in release mode while being blank in debug mode.

@psigen
Copy link
Collaborator Author

psigen commented Apr 18, 2017

I noted two options that might make this easier. You might already know about these:

  1. There is a noexcept operator which performs a compile-time check whether an expression can produce an exception. We might be able to use this in DART unit tests to verify that certain components never throw exceptions.
    http://en.cppreference.com/w/cpp/language/noexcept

  2. The noexcept specifier can optionally take an expression which evaluates to a boolean indicating whether or not the marked function should be noexcept. It seems like we could potentially simply pass the DART debug flag trivially as a constexpr instead of macroing it.
    http://en.cppreference.com/w/cpp/language/noexcept_spec

@stale
Copy link

stale bot commented Feb 13, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Feb 13, 2018
@stale stale bot removed the stale label Feb 13, 2018
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

2 participants