ApplicationException or create custom exceptions?

前端 未结 4 1354
天涯浪人
天涯浪人 2021-01-18 02:12

In my file repository, I will throw the following exceptions when the InsertFile() method is called:

  • When the upload file size limit is exceeded
4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-18 02:48

    Maybe read the documentation:

    If you are designing an application that needs to create its own exceptions, you are advised to derive custom exceptions from the Exception class. It was originally thought that custom exceptions should derive from the ApplicationException class; however in practice this has not been found to add significant value.

    As to whether there are better exceptions to throw - some might consider throwing an ArgumentOutOfRangeException if you don't want to define your own exception.

提交回复
热议问题