In C++ what are the benefits of using exceptions and try / catch instead of just returning an error code?

后端 未结 13 887
遥遥无期
遥遥无期 2020-12-04 19:58

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 retur

13条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-04 20:30

    Here's a good explanation of EAFP ("Easier to Ask for Forgiveness than Permission."), which I think applies here even if it's a Python page in Wikipedia. Using exceptions leads to a more natural style of coding, IMO -- and in the opinion of many others, too.

提交回复
热议问题