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

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

    Exception specifications are pretty useless in C++.

    It's not enforced that no other exceptions will be thrown, but merely that the global function unexpected() will be called (which can be set)

    Using exception specifications mainly boils down to deluding yourself (or your peers) into some false sense of security. Better to simply not bother.

提交回复
热议问题