Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why don't you have to explicitly declare that you might throw some built in exceptions in Java?

Tags:

java

exception

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?

like image 573
Omar Kooheji Avatar asked Feb 09 '09 16:02

Omar Kooheji


1 Answers

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 )

like image 136
OscarRyz Avatar answered Oct 04 '22 21:10

OscarRyz