Hacker News new | ask | show | jobs
by alanfranz 531 days ago
> certain scale

Make it explicit. If the array is too large, throw an IllegalArgumentException. Document the limit. Then I agree with you.

Otherwise, if an allowed input crashes the program at runtime with a random exception, I respectfully disagree.

2 comments

IllegalArgumentException is OK in your book, but OverflowException is not? It's very rare that I actually care which exception type is thrown, but it's a little more polite to throw more clear and reliable exception types. But saying "this could be a little more polite and therefore YOUR CODE HAS A BUG" would make me never want to work with you again.
Explict OverflowException could be ok but it may not tell me the root cause. A random index error is not ok at any time.
Then you should absolutely stay away from C :)
Words to live by!
I do.

But the example was Java.