I know about unchecked exception that occurs at run time but don't know about checked. I found a video says checked exception and unchecked exception occurs at run time only. Also found a website which says checked exception occurs at compile time. I use Java 8 Documentation but didn't find when checked exception occurs at compile time or at run time. If you read in Java Documentation please give me reference if possible.
All exceptions (except those thrown by the compiler when you try to compile bad code) are always thrown at runtime. The difference between checked and unchecked (sub-classes of RuntimeException) exceptions is whether the compiler forces you to write code that handles the exception.
The compiler will throw an exception during compilation, but it's not the same exception as the one thrown in bar(). The exception thrown in bar() (after you declare that the method throws a checked exception) will still only be thrown during runtime of your application.
Stephan van Hulst
posted 3 years ago
RuntimeException really is a misnomer. They should have called it CheckedException instead.
Stephan van Hulst wrote:RuntimeException really is a misnomer. They should have called it CheckedException instead.
UncheckedException, you mean?
The theory is that the runtime Exception occurs entirely within the Java® runtime rather than at the interface between Java® and other code. An IOException occurs when you attempt to access the hard drive or network or keyboard, for example. That is why they called in runtime Exception. At least that it the theory; most people can find exceptions to that notion.