Many people say that checked exceptions (i.e. these that you should explicitly catch or rethrow) should not be used at all. They were eliminated in C# for example, and most languages don't have them. So you can always throw a subclass of RuntimeException (unchecked exception).

However, I think checked exceptions are useful - they are used when you want to force the user of your API to think how to handle the exceptional situation (if it is recoverable). It's just that checked exceptions are overused in the Java platform, which makes people hate them.

Here's my extended view on the topic.

As for the particular questions:

  1. Is the NumberFormatException considered a checked exception?
    No. NumberFormatException is unchecked (= is subclass of RuntimeException). Why? I don't know. (but there should have been a method isValidInteger(..))

  2. Is RuntimeException an unchecked exception?
    Yes, exactly.

  3. What should I do here?
    It depends on where this code is and what you want to happen. If it is in the UI layer - catch it and show a warning; if it's in the service layer - don't catch it at all - let it bubble. Just don't swallow the exception. If an exception occurs, in most of the cases, you should choose one of these:

  • log it and return
  • rethrow it (declare it to be thrown by the method)
  • construct a new exception by passing the current one in constructor
  1. Now, couldn't the above code also be a checked exception? I can try to recover the situation like this? Can I?
    It could've been. But nothing stops you from catching the unchecked exception as well.

  2. Why do people add class Exception in the throws clause?
    Most often because people are lazy to consider what to catch and what to rethrow. Throwing Exception is a bad practice and should be avoided.

Alas, there is no single rule to let you determine when to catch, when to rethrow, when to use checked and when to use unchecked exceptions. I agree this causes much confusion and a lot of bad code. The general principle is stated by Bloch (you quoted a part of it). And the general principle is to rethrow an exception to the layer where you can handle it.

Answer from Bozho on Stack Overflow
🌐
Scaler
scaler.com › topics › checked-exception-in-java
What Is Checked Exception in Java? - Scaler Topics
October 7, 2022 - ClassNotFoundException : It is a kind of checked exception that occurs when a Java virtual machine (JVM) tries to load a class but fails because it is unable to find the classpath. Since it is a checked exception, it should be handled explicitly by using the try-catch block or by using the throws keyword. InterruptedException : It usually occurs when a thread is interrupted while waiting or sleeping or occupied in some task.
🌐
Baeldung
baeldung.com › home › java › checked and unchecked exceptions in java
Checked and Unchecked Exceptions in Java | Baeldung
January 8, 2024 - In general, checked exceptions represent errors outside the control of the program. For example, the constructor of FileInputStream throws FileNotFoundException if the input file does not exist. Java verifies checked exceptions at compile-time.
Discussions

Understanding checked vs unchecked exceptions in Java - Stack Overflow
Joshua Bloch in "Effective Java" said that Use checked exceptions for recoverable conditions and runtime exceptions for programming errors (Item 58 in 2nd edition) Let's see if I understan... More on stackoverflow.com
🌐 stackoverflow.com
If everyone hates checked exceptions, where's the alternative?
What you're observing is that for any endeavor, the haters often dominate the discourse, even when they don't have a majority position or a credible alternative. If they didn't hate on exceptions, they'd be whining about something else. Error handling is hard; there are many different approaches (C-style single return codes, Go-style multiple return codes, unchecked exceptions, checked exceptions, try monads, and more), and each has their pros and cons (and their supporters and haters), striking different balances of reliability and intrusiveness. Thinking there is One True Best Way here is fantasy. When people react to a particular error model, they are often reacting not to the approach itself, but examples they've encountered where it is used poorly. (Certainly Java has no shortage of examples of checked exceptions being misused.) The reality is that checked exceptions are OK, and they're what we've got, and, even if there was something that was slightly better, the disruption of trying to migrate billions of lines of code would make that impractical -- it would have to be massively better, and there's no such candidate on the horizon. Most developers intuitively realize this, and are not interested in dying on this hill, so you don't hear them in the vocal discourse, because they're too busy getting their work done. So if you want to know what to tell the newbies, tell them: don't take every rant seriously, some people just like to rant. More on reddit.com
🌐 r/java
93
16
April 25, 2024
Some thoughts: The real problem with checked exceptions
Checked exceptions weren’t such a big issue to me if Java's Lambda implementation wouldn’t have been done the way it has been done and if checked exceptions would be easily propagated outside of Lambda calls. But because Lambda calls are beautified anonymous classes with abstract methods that often don’t declare exceptions as part of their method you can’t easily do that and that makes handling checked exceptions as part of Lambdas super ugly. More on reddit.com
🌐 r/java
189
35
June 1, 2024
Why are checked exceptions frowned upon?
In programming there are few absolutes. And exceptions are no exception. More on reddit.com
🌐 r/java
101
74
August 26, 2020
🌐
TheServerSide
theserverside.com › answer › What-are-checked-vs-unchecked-exceptions-in-Java
What are checked vs. unchecked exceptions in Java? | TheServerSide
Some exceptions in Java must be handled in the developer's code. Other exceptions can occur without any exception handling semantics at all. When an exception must be handled with try-and-catch semantics, it is known as a checked exceptions.
Published   April 18, 2022
🌐
Rollbar
rollbar.com › home › how to handle checked & unchecked exceptions in java
How to Handle Checked & Unchecked Exceptions in Java | Rollbar
July 5, 2024 - In broad terms, a checked exception (also called a logical exception) in Java is something that has gone wrong in your code and is potentially recoverable. For example, if there’s a client error when calling another API, we could retry from ...
🌐
How to do in Java
howtodoinjava.com › home › exception handling › java checked vs unchecked exceptions
Java - Checked vs Unchecked Exceptions (with Examples)
December 20, 2022 - In Java, exceptions are broadly categorized into two sections: ... The checked exceptions are those exceptions, as the name suggests, which a method must handle in its body or throw to the caller method so the caller method can handle it.
🌐
Oracle
docs.oracle.com › javase › specs › jls › se7 › html › jls-11.html
11.2. Compile-Time Checking of Exceptions
September 16, 2025 - To take advantage of compile-time checking for exception handlers (§11.2), it is typical to define most new exception classes as checked exception classes, that is, as subclasses of Exception that are not subclasses of RuntimeException. ... A throw statement (§14.18) was executed. An abnormal execution condition was synchronously detected by the Java Virtual Machine, namely: evaluation of an expression violates the normal semantics of the Java programming language (§15.6), such as an integer divide by zero.
🌐
BeginnersBook -
beginnersbook.com › home › java › checked and unchecked exceptions in java with examples
Checked and unchecked exceptions in java with examples
October 25, 2022 - There are two types of exceptions: checked exception and unchecked exception. In this guide, we will discuss them. The main difference between checked and unchecked exception is that the checked exceptions are checked at compile-time while unchecked exceptions are checked at runtime.
Find elsewhere
Top answer
1 of 16
521

Many people say that checked exceptions (i.e. these that you should explicitly catch or rethrow) should not be used at all. They were eliminated in C# for example, and most languages don't have them. So you can always throw a subclass of RuntimeException (unchecked exception).

However, I think checked exceptions are useful - they are used when you want to force the user of your API to think how to handle the exceptional situation (if it is recoverable). It's just that checked exceptions are overused in the Java platform, which makes people hate them.

Here's my extended view on the topic.

As for the particular questions:

  1. Is the NumberFormatException considered a checked exception?
    No. NumberFormatException is unchecked (= is subclass of RuntimeException). Why? I don't know. (but there should have been a method isValidInteger(..))

  2. Is RuntimeException an unchecked exception?
    Yes, exactly.

  3. What should I do here?
    It depends on where this code is and what you want to happen. If it is in the UI layer - catch it and show a warning; if it's in the service layer - don't catch it at all - let it bubble. Just don't swallow the exception. If an exception occurs, in most of the cases, you should choose one of these:

  • log it and return
  • rethrow it (declare it to be thrown by the method)
  • construct a new exception by passing the current one in constructor
  1. Now, couldn't the above code also be a checked exception? I can try to recover the situation like this? Can I?
    It could've been. But nothing stops you from catching the unchecked exception as well.

  2. Why do people add class Exception in the throws clause?
    Most often because people are lazy to consider what to catch and what to rethrow. Throwing Exception is a bad practice and should be avoided.

Alas, there is no single rule to let you determine when to catch, when to rethrow, when to use checked and when to use unchecked exceptions. I agree this causes much confusion and a lot of bad code. The general principle is stated by Bloch (you quoted a part of it). And the general principle is to rethrow an exception to the layer where you can handle it.

2 of 16
257

Whether something is a "checked exception" has nothing to do with whether you catch it or what you do in the catch block. It's a property of exception classes. Anything that is a subclass of Exception except for RuntimeException and its subclasses is a checked exception.

The Java compiler forces you to either catch checked exceptions or declare them in the method signature. It was supposed to improve program safety, but the majority opinion seems to be that it's not worth the design problems it creates.

Why do they let the exception bubble up? Isnt handle error the sooner the better? Why bubble up?

Because that's the entire point of exceptions. Without this possibility, you would not need exceptions. They enable you to handle errors at a level you choose, rather than forcing you to deal with them in low-level methods where they originally occur.

🌐
Reddit
reddit.com › r/java › if everyone hates checked exceptions, where's the alternative?
r/java on Reddit: If everyone hates checked exceptions, where's the alternative?
April 25, 2024 -

Many a blog post has been written about how Checked Exception are bad/the devil incarnate.

For all the bloviating about how bad it is, most of these articles and their comment sections lack any concrete alternatives.

For Java versions before 21, there simply doesn't seem to be a reasonable (never mind close to standardized) alternative to express that a method returns Thing or AException or BException.

For Java 21+, with sealed classes and exhaustive switches, you kind of can manually recreate a vague resemblance of e.g. Rusts Result Type. That will still lack some necessities, like enforcing checking the Error for Void methods (as in Result<Void, Err>).

So my question is:

  • If you agree that checked exceptions are bad, what alternative are you actively using right now?

  • How is your favorite library handling this? Because most still seem to use exceptions

Personally, I'm getting reaaaallly annoyed by the way people talk about exceptions online. For one, they'll point out a problem, but then fail to demonstrate a solution that wouldn't have it. For another, there's very little will, it seems, to suggest and work towards a serious alternative. How can we, as a community, warn against using a builtin feature for an important part of programming without providing alternatives? Aren't we simply screwing over newbies with these takes?

Top answer
1 of 24
22
Checked exceptions are the right tool for the job they're designed for, they simply get misused. An unexpected error but there are ways to recover -> checked exception. Example : Server unavailable. Recovery possibility: retry the operation at a later time. If there is not a way to recover it should not be a checked exception. It should be an unchecked exception. Example -> NullPointer. Something is not right somewhere, and retrying isn't going to fix it. If it is not an unexpected error (example, user enters their born on date in the future) then it should not be an exception. This should be a validation that returns some validation result, maybe just true or false, maybe a validationResult class of some sort.
2 of 24
14
What you're observing is that for any endeavor, the haters often dominate the discourse, even when they don't have a majority position or a credible alternative. If they didn't hate on exceptions, they'd be whining about something else. Error handling is hard; there are many different approaches (C-style single return codes, Go-style multiple return codes, unchecked exceptions, checked exceptions, try monads, and more), and each has their pros and cons (and their supporters and haters), striking different balances of reliability and intrusiveness. Thinking there is One True Best Way here is fantasy. When people react to a particular error model, they are often reacting not to the approach itself, but examples they've encountered where it is used poorly. (Certainly Java has no shortage of examples of checked exceptions being misused.) The reality is that checked exceptions are OK, and they're what we've got, and, even if there was something that was slightly better, the disruption of trying to migrate billions of lines of code would make that impractical -- it would have to be massively better, and there's no such candidate on the horizon. Most developers intuitively realize this, and are not interested in dying on this hill, so you don't hear them in the vocal discourse, because they're too busy getting their work done. So if you want to know what to tell the newbies, tell them: don't take every rant seriously, some people just like to rant.
🌐
Medium
medium.com › @AlexanderObregon › the-difference-between-checked-and-unchecked-exceptions-in-java-for-beginners-c3943786c40a
The Difference between Checked and Unchecked Exceptions in Java for Beginners
January 15, 2024 - The primary purpose of checked exceptions is to ensure that error handling is not ignored by the developer. By requiring these exceptions to be either caught or declared, Java ensures that the programmer is aware of potential issues and takes ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-checked-vs-unchecked-exceptions
Java Checked vs Unchecked Exceptions - GeeksforGeeks
October 2, 2025 - In Java, exceptions under Error and RuntimeException classes are unchecked exceptions, everything else under throwable is checked.
🌐
Oracle
docs.oracle.com › javase › tutorial › essential › exceptions › catchOrDeclare.html
The Catch or Specify Requirement (The Java™ Tutorials > Essential Java Classes > Exceptions)
But sometimes the user supplies the name of a nonexistent file, and the constructor throws java.io.FileNotFoundException. A well-written program will catch this exception and notify the user of the mistake, possibly prompting for a corrected file name. Checked exceptions are subject to the Catch or Specify Requirement. All exceptions are checked exceptions, except for those indicated by Error, RuntimeException, and their subclasses.
🌐
Coding Shuttle
codingshuttle.com › java-programming-handbook › checked-and-unchecked-exceptions
Checked vs Unchecked Exceptions in Java: Ultimate Guide | Coding Shuttle
July 24, 2025 - Checked exceptions are exceptions that must be handled using a try-catch block or declared using throws in the method signature. If not handled, the compiler will throw an error. ... import java.io.File; import java.io.FileReader; import ...
🌐
Quora
quora.com › What-are-checked-and-unchecked-exceptions-in-Java-2
What are checked and unchecked exceptions in Java? - Quora
Answer: 1. Checked Exceptions: - Definition: These are exceptions that are checked at compile-time. The Java compiler forces you to handle these exceptions, either by using a `try-catch` block or by declaring them with the `throws` keyword.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-program-to-handle-checked-exception
Java Program to Handle Checked Exception - GeeksforGeeks
July 23, 2025 - All the exceptions throw objects when they occur try statement allows you to define a block of code to be tested for errors and catch block captures the given exception object and perform required operations. Using a try-catch block defined output will be shown. ... // Java Program to Illustrate Handling of Checked Exception // Importing required classes import java.io.*; import java.util.*; // Main class class GFG { // Main driver method public static void main(String[] args) throws FileNotFoundException { // Assigning null value to object of FileInputStream FileInputStream GFG = null; // Try
🌐
Studyeasy
studyeasy.org › course-articles › java-en-en › s07l34-checked-and-unchecked-exception-in-java
S07L34 – Checked and unchecked exception in Java – Studyeasy
By the end of this guide, you’ll have a clear understanding of when to use each type of exception, backed by practical examples and comparative analysis. Checked exceptions are exceptions that are checked at compile-time. This means that the Java compiler ensures that these exceptions are ...
🌐
Deep Blogs
blog.deepdhamala.com.np › posts › checked-vs-unchecked
Checked vs Unchecked Exceptions in Java - Deep Blogs
July 27, 2025 - Examples of checked exceptions include IOException, SQLException, and ClassNotFoundException. These exceptions must be either caught using a try-catch block or declared in the method signature using the throws keyword.
🌐
W3Schools
w3schools.com › java › java_try_catch.asp
Java Exceptions (Try...Catch)
As mentioned in the Errors chapter, different types of errors can occur while running a program - such as coding mistakes, invalid input, or unexpected situations. When an error occurs, Java will normally stop and generate an error message. The technical term for this is: Java will throw an exception (throw an error).
🌐
GeeksforGeeks
geeksforgeeks.org › java › exceptions-in-java
Java Exception Handling - GeeksforGeeks
There are two type of built-in exception in java. Checked Exception: These exceptions are checked at compile time, forcing the programmer to handle them explicitly.
Published   3 weeks ago
🌐
Wikipedia
en.wikipedia.org › wiki › Exception_handling_(programming)
Exception handling (programming) - Wikipedia
2 weeks ago - In Java, a checked exception specifically is any Exception that does not extend RuntimeException. The checked exceptions that a method may raise must be part of the method's signature. For instance, if a method might throw a java.io.IOException, it must declare this fact explicitly in its method ...