Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe to use the throw() suffix on a function containing std::string?

I have a member function that doesn't throw anything so i appended the throw() suffix to the end of it, indicating that it won't throw any exceptions.

My question is, in the function I make use of several std::string, and lets say something goes wrong in the initialization of the std::string, and it throws bad_alloc or out_of_range (or what ever else can go wrong with a std::string).

Is it still safe to still add the throw() suffix?

like image 826
Josh Avatar asked Feb 21 '23 18:02

Josh


1 Answers

Herb Sutter says that

exception specifications confer a lot less benefit than they're worth

It can cause more problems than bring benefits. So, you should think twise before doing that.

like image 53
D_E Avatar answered Feb 24 '23 17:02

D_E