Are exceptions in php really that useful?

后端 未结 9 2306
猫巷女王i
猫巷女王i 2021-02-08 14:48

3 days ago I started rewriting one of my scripts in OOP using classes as a practice after reading a lot about the advantages of using OOP.

Now I\'m confused weather I sh

9条回答
  •  北海茫月
    2021-02-08 15:47

    Exceptions as an error handling mechanism are VERY different in concept and implementation than function return codes. You cannot/should not simply map one to the other. You should read and digest this article (and then a few more including this one*) before proceeding further.

    If you're going to favor exceptions instead of return codes for error reporting/handling then the structure of your code should change significantly.

    (*The CodeProject link is .NET-specific but there's little code ti digest. It's mostly a best-practices article easily applicable to any language.)

提交回复
热议问题