What exception to throw from a property setter?

后端 未结 7 2119
醉话见心
醉话见心 2020-12-08 02:24

I have a string property that has a maximum length requirement because the data is linked to a database. What exception should I throw if the caller tries to set a string ex

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-08 02:50

    To me ArgumentException (or a child) makes more sense, because the argument (value) you provided is not valid, and this is what ArgumentException was created for.

提交回复
热议问题