C++ - Arguments for Exceptions over Return Codes

后端 未结 11 1647
鱼传尺愫
鱼传尺愫 2020-11-29 21:10

I\'m having a discussion about which way to go in a new C++ project. I favor exceptions over return codes (for exceptional cases only) for the following reasons -

11条回答
  •  一向
    一向 (楼主)
    2020-11-29 21:40

    As a general rule. when recovery is possible and expected then use return codes.

    When recovery is not possible or not desired then use exceptions.

    Error handling is difficult, writing clean code with and without exceptions is - difficult.

    As this is a new project, you don't have to worry about making old code exception safe, however you do have to worry about writing clean clear code.

    Do so by using exceptions where appropriate.

提交回复
热议问题