Why aren't exceptions in C++ checked by the compiler?

前端 未结 6 1685
广开言路
广开言路 2020-12-13 17:45

C++ provides a syntax for checked exceptions, for example:

void G() throw(Exception);
void f() throw();

However, the Visual C++ compiler do

6条回答
  •  天命终不由人
    2020-12-13 18:07

    I cannot check this for lack of a MSVC installation, but are you really sure the compiler ignores the throw() specification?

    This MSDN page suggests that Microsoft is aware of throw() and expects their compiler to handle it correctly. Well, almost, see the note about how they depart from the ANSI/ISO standard in some details.

    Edit: In practice, though, I agree with Patrick: Exception specifications are mostly useless.

提交回复
热议问题