Debug.Assert vs Exceptions

前端 未结 8 1131
面向向阳花
面向向阳花 2020-12-13 21:03

Surprisingly I was only able to find one previous question on SO about this subject, and I\'d just like to get the community \"Vote of Confidence\" (or not!) on my approach.

8条回答
  •  伪装坚强ぢ
    2020-12-13 21:56

    Often both: Assert, then throw.

    You assert because you want to notify developers of a mistaken assumption during development.

    You throw because if this happens in a release build, you need to make sure the system doesn't continue processing while in a bad state.

    The desired reliability characteristics of your system may affect your choice here, but 'assert then throw' is often a useful strategy, I think.

提交回复
热议问题