Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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?

like image 285
RichK Avatar asked Apr 04 '11 16:04

RichK


2 Answers

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

like image 179
BrandonZeider Avatar answered Sep 21 '22 13:09

BrandonZeider


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. :-)

like image 24
Timwi Avatar answered Sep 21 '22 13:09

Timwi