BridgesUNCC / bridges-cxx

C++ client library for Bridges
http://bridgesuncc.github.io
2 stars 5 forks source link

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

Open prestoncarman opened 3 years ago

prestoncarman commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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: