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

前端 未结 6 1693
广开言路
广开言路 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:02

    Because the standard says so. The exception declaration doesn't mean that no other exception will be thrown. It means that if an undeclared exception is thrown, there will be called a special global function called unexpected(), which by default terminates the program. Generally declaring exceptions in functions is discouraged (maybe except for empty exception list) as the standard behaviour is not very helpful.

提交回复
热议问题