不允许 C++\CLI 异常规范
I'm an experienced unmanaged C++ developer, new to C++\CLI.
How come managed C++ doesnt allow exception specification?
Example link
What's the best practice for specifying exceptions my methods throw then?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
大概是因为 CLR 不使用异常规范; 这大概是因为微软在研究 Java 后认为它们带来的麻烦远远超过了它们的价值。
因此,指定方法抛出哪些异常的最佳实践是不要打扰,即删除异常规范。 值得指出的是,即使在正常的 C++(即本机)世界中,大多数人要么完全避开异常规范,要么仅使用空规范来指示该方法不会抛出异常。
Presumably because the CLR doesn't use exception specifications; this in turn is presumably because Microsoft looked at Java and decided that they are far more trouble than they are worth.
So the best practice for specifying what exceptions your methods throw is to not bother, ie remove your exception specs. It's worth pointing out that even in the normal C++ (ie native) world most people either eschew exception specifications entirely, or only use the empty specification to indicate that the method does not throw.