开发者

ArgumentException for a Combination of Arguments

I have a method that takes three parameters (3D points). I want to throw an exception if the points are colinear. The obvious exception to me is Argument开发者_运维技巧Exception, but the best practise with this is to include the param name in the constructor. In my case it's the combination of all three params which is the invalid input - so the best practise isn't going to work (and I think my code analysis will moan like hell).

So do I use ArgumentException here or something like InvalidOperationException because there's more than one parameter causing the problem?


Try creating your own Exception type, deriving from ArgumentException. In that class you can store all three parameters.


I think both are fine.

If you choose to use ArgumentException, you can use the name of any one parameter. Personally I would use the name of the last parameter. After all, if the points are collinear, you need to change only one and then all the parameters are fine. :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜