I'm writing a program that will perform matrix operations, and I'm trying to figure out what kind of exeption I should use in case of invalid dimensions. Is there some exception type that already exists that would be acceptable for my operations to throw; or should I implement my own exception type? I know that pretty much any exception type would do what I want, but the issue is making sure that the exception actually describes the problem that caused it.
The closest fit for what you are looking for is the IndexOutOfBoundsException
. You can use it as-is, or derive your own MatrixIndexOutOfBoundsException
exception from it.
Like others say, you probably don't need to. But since customer is always right - You should create your own exception type.
Here's a related SO question though : Exception in thread "main" java.lang.RuntimeException: Matrix is singular
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