You say that you will need to check all the RuntimeExceptions
. The answer to this question is no! It is normal for the API to throw unchecked exceptions at runtime (whether it is NullPointerException
, IllegalArgumentException
or something else) in case it is used incorrectly.
In your case, you are using the API incorrectly, so you get a NullPointerException
. If you want to understand this, what would your code look like?
try { useAPI(); } catch(NullPointerException e) { useAPIcorrectly(); }
Why not do it just useAPIcorrectly();
?; -)
You can add some debugging result to the catch block for development, but again: if in development, the NullPointerException
stack trace is also sufficient for debugging. Then you will fix it to use the API correctly and you will never see these exceptions :-)
source share