I've noticed with Integer.parseInt()
that you don't have to surround it with a try catch or declare that the method might throw an exception, despite the fact that it "throws" a NumberFormatException
.
Why don't I have to explicitly catch the NumberFormatException
or state that my method throws it?
Because that is a "runtime" exception.
RuntimeExceptions are used to identify programming problems ( that a good programmer could avoid ) while
Checked exceptions are to identify environment problems ( that could not be avoided no matter how good do you program , a server is down for instance )
You could read more about them here
There are actually three kinds of exceptions, only one of them should be handled ( most of the times )
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