在C ++中,使用异常和try / catch的好处是什么,而不是只返回一个错误代码? [英] In C++ what are the benefits of using exceptions and try / catch instead of just returning an error code?

查看:170
本文介绍了在C ++中,使用异常和try / catch的好处是什么,而不是只返回一个错误代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编程C和C ++很长一段时间,到目前为止,我从来没有使用异常和try / catch。使用它而不是只有函数返回错误代码的好处是什么?

I've programmed C and C++ for a long time and so far I've never used exceptions and try / catch. What are the benefits of using that instead of just having functions return error codes?

推荐答案

很明显,开发人员可以忽略有些失败。

Possibly an obvious point - a developer can ignore (or not be aware of) your return status and go on blissfully unaware that something failed.

异常需要以某种方式确认 - 它不能默默地被忽略,而不会积极地做到这一点。

An exception needs to be acknowledged in some way - it can't be silently ignored without actively putting something in place to do so.

这篇关于在C ++中,使用异常和try / catch的好处是什么,而不是只返回一个错误代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆