I made a Matrix implementation which has an overloaded operator *. If there’re 2 matricies of incompatible sizes I’d like to throw either ArgumentException or InvalidOperationException. Which one should I use? Or maybe it’s move convenient to declare my own?
I made a Matrix implementation which has an overloaded operator * . If there’re
Share
Definitely create your own
MismatchingDimensionsException.Your users won’t be confused by such an exception, they’ll know what the problem is right away. It’s the kind of problem that can happen a lot when dealing with matrices.
Now, do you derive it from ArgumentException or InvalidOperationException? I would say the former, but the latter makes just as much sense. If you use your own exception class, it matters less.