Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exception type should I use?

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.

like image 889
AJMansfield Avatar asked Sep 24 '12 17:09

AJMansfield


Video Answer


2 Answers

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 image 181
Sergey Kalinichenko Avatar answered Oct 01 '22 00:10

Sergey Kalinichenko


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

like image 39
Caffeinated Avatar answered Sep 30 '22 23:09

Caffeinated