Why not use exceptions as regular flow of control?

后端 未结 24 1824
心在旅途
心在旅途 2020-11-21 07:30

To avoid all standard-answers I could have Googled on, I will provide an example you all can attack at will.

C# and Java (and too many others) have with plenty of ty

24条回答
  •  名媛妹妹
    2020-11-21 08:05

    Here are best practices I described in my blog post:

    • Throw an exception to state an unexpected situation in your software.
    • Use return values for input validation.
    • If you know how to deal with exceptions a library throws, catch them at the lowest level possible.
    • If you have an unexpected exception, discard current operation completely. Don’t pretend you know how to deal with them.

提交回复
热议问题