Alex Rivera | Logout

Why is NullPointerException not declared as a checked exception

Asked 2010-04-21T14:45:45.223
25

This was the question asked in an interview. NullPointerException is very common; why is it not declared as a checked exception? I googled but did not get a proper answer.

Edit
Report

1 Answer

4

The one sentence answer I would give is that it is the result of a programming error, and programming error exceptions are not checked exceptions (IllegalStateException, ClassCastException, etc.).

But even if you had an argument for why it should maybe be a checked exception, basically every operation on an object reference can throw it, so it would be all over the place and literally every method in a non-trivial program would have to throw it - so what would be the point?

answered 2010-04-21T14:49:59.867

Your Answer