When should I use a ThrowHelper method instead of throwing directly?

前端 未结 6 1729
傲寒
傲寒 2021-02-05 10:16

When is it appropriate to use a ThrowHelper method instead of throwing directly?

void MyMethod() {
    ...
    //throw new ArgumentNullException(\"param         


        
6条回答
  •  不知归路
    2021-02-05 10:45

    I would say that the only reasonable time to do this is in something like the BCL where the amount of usage of the class is wide spread enough that the savings may be worth it. It would have to make sense, however. In your case, I don't think you're actually saving any space. Instances of ThrowHelper in the BCL reduce size by substituting enums for strings and method calls (to get string messages). Your case simply passes the same arguments and thus doesn't achieve any savings. It costs just as much to call your method as it does to throw the exception in place.

提交回复
热议问题