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

Update throws to use an exception instead of a string literal #113

Open
prestoncarman opened this issue May 11, 2021 · 3 comments
Open

Update throws to use an exception instead of a string literal #113

prestoncarman opened this issue May 11, 2021 · 3 comments
Assignees

Comments

@prestoncarman
Copy link

https://stackoverflow.com/questions/27179011/c-exception-throw-a-string

Its not a good idea to throw a string. It should be a C++ Exception. Search the repository and replace each throw with an appropriate exception.

@esaule
Copy link
Member

esaule commented May 11, 2021

Hello @prestoncarman

I agree with the sentiment. But I am not sure how to make that so that it is most helpful. Do you know of any guidelines, design structures, best practices, that should be followed when using exceptions in C++?

In particular it seems that the community has been going back and force on whether the function prototype should explicitely indicate that they throw exceptinos or not.

Can you point us in the right direction maybe?

@prestoncarman
Copy link
Author

Hi @esaule,

To find some answers to your question about standards, I went to two of my c++ textbooks and found they had different points of view (one for strings, the other for exception classes). Then I decided to check out the Google Style guidelines https://google.github.io/styleguide/cppguide.html#Exceptions in which they say to not use exceptions at all. This is primarily because they have a large enough code base without exceptions. It appears not easy to integrate exception code with non-exception code and so they will continue without exceptions in their code, although they do have an exemption for Windows based code.

Jumping to Microsoft, I found a nice developers guide https://docs.microsoft.com/en-us/cpp/cpp/exception-handling-in-visual-cpp?view=msvc-160 to using exceptions in C++ code. I guess this could be a good model to follow.

@esaule
Copy link
Member

esaule commented Jun 21, 2021

We are still looking into this. We'll probably make some changes during summer. I am still collecting ressources on how to use exceptions properly to be as useful as possible.

This seems like a place to start:

@esaule esaule self-assigned this Jun 21, 2021
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