When to use an assertion and when to use an exception

前端 未结 11 2120
暖寄归人
暖寄归人 2020-11-27 09:28

Most of the time I will use an exception to check for a condition in my code, I wonder when it is an appropriate time to use an assertion?

For instance,



        
11条回答
  •  被撕碎了的回忆
    2020-11-27 09:48

    You can use this simple difference in mind while their usage. Exceptions will be used for checking expected and unexpected errors called checked and unchecked error while assertion is used mainly for debugging purposes at the run time to see whether the assumptions are validated or not.

提交回复
热议问题