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 ArgumentException
, 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. :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With