Throw keyword in function's signature

c++, exception

Solution

No, it is not considered good practice. On the contrary, it is generally considered a bad idea.

http://www.gotw.ca/publications/mill22.htm goes into a lot more detail about why, but the problem is partly that the compiler is unable to enforce this, so it has to be checked at runtime, which is usually undesirable. And it is not well supported in any case. (MSVC ignores exception specifications, except throw(), which it interprets as a guarantee that no exception will be thrown.

Problem

What is the technical reason why it is considered bad practice to use the C++ `throw` keyword in a function signature? ``` bool some_func() throw(myExc) { ... if (problem_occurred) { throw myExc("problem occurred"); } ... } ```

Original source

Related problems