[General boards] [Fall 2018 courses] [Summer 2018 courses] [Winter 2018 courses] [Older or newer terms]

When does checked exception gets checked


From my understanding, if a checked exception exists the program cannot compile, also in oracles it says the compiler checks the checked exception during compilation. From my personal experience this is true as well…
However as I read some post on stackoverflow, they says all exception gets checked during runtime?
Now I’m confused. Can someone please explain this to me.


“Checked” means that the compiler looks for “throws ABCException” in the class signature. If “throws ABCException” is present, it looks for a try and catch block.

The compiler DOES NOT check to see which type of exception is thrown and whether or not that matches the exception inside: “catch (XYZExcption e) {…}”. This is checked at runtime.

The difference is this:
In the first case, it is possible to read the code and decide if a method is being called from within a try block. In the second case, we can only know which exception is thrown after we know which path through execution is being taken. (For example, did we go through the true or false branch of an if statement?)