0

I never use exceptions in my code and never will. Is it sain to add noexcept to every possible function?

What happens if a user that uses my code is using exceptions (feel sorry for him) where there are internal function calls like stl stuff that may throw?

  • 2
    Does this answer your question? [When should I really use noexcept?](https://stackoverflow.com/questions/10787766/when-should-i-really-use-noexcept) – con ko May 13 '20 at 05:30
  • This happens: "Non-throwing functions are permitted to call potentially-throwing functions. Whenever an exception is thrown and the search for a handler encounters the outermost block of a non-throwing function, the function std::terminate is called" ([cppreference](https://en.cppreference.com/w/cpp/language/noexcept_spec)). But it's not in that "poor" users hand to decide whether a function you use internally throws and causes the program to terminate. – StefanKssmr May 13 '20 at 05:57
  • I'v read it John Ding. Interesting reading but no one ever mentions when exceptions are turned off is noexcept usefull in that case or not. In fact I'm asking this question because I have serached allot and didnt find anything. – Alex Wennström May 13 '20 at 06:24
  • Thanks Stefan, you right, noexcept tells that this particular function does not not throw exceptions itself but internal function calls can. – Alex Wennström May 13 '20 at 06:26
  • Actually there is a guy in the post above that has a good point, why didn't they made a design where you instead of noexcept tell that the function will throw, that would save allot of redundant typing. – Alex Wennström May 13 '20 at 06:28

0 Answers0