我如何检查结果的类型是否正确(int、float、double 等),然后抛出异常并捕获异常?
谢谢大家
弗拉德。
最佳答案
您能否详细说明是什么给了您“结果”,您可以从那里确定您需要什么,而且更有可能以更好的方式确定。
如果您真正想要的只是检查类型,请使用 typeid
.
更多信息 here
按照 Daniel 的编辑帖子模型,在陈述其他内容后实际回答问题...
来 self 的其他评论:
You have to do this BEFORE you have just the result. Checking for overflow after is not a good idea. Do a check on the numbers before adding to see if they will overflow, or restrict input to be less than half the max value of the type
关于c++ - 在 C++ 中捕获类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1346989/