What is the difference between an error and an exception in .NET?

前端 未结 8 1922
说谎
说谎 2021-02-02 12:28

Could you please explain to me what the difference is between an error and an exception?

8条回答
  •  无人共我
    2021-02-02 13:20

    Usually, I classify them as:

    Error - is a known workflow within the application. For example: Username not provided during authentication is an error.
    The application can handle these situation & will be able to show friendly messages to the user to prompt for proper input and/or process the data in a different.

    Exception - is usually throw when going out of your system and/or something unexpected happens in the application. For example: opening a file handle might throw an exception due to insufficient rights or the file not existing.
    Usually in this case, the application can catch these exception and/or write a generic handler to handle all the exceptions in the system.

    As a rule of thumb, if you know a particular case exists due to which the application cannot proceed working, label it as an error & handle the case gracefully.

    All remaining 'unknown-unknows' can then fall into the category of Exceptions.

    HTH.

提交回复
热议问题