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
🌐
Medium
medium.com › @ahmed.abdelfaheem › checked-and-unchecked-exceptions-in-java-6cb1c9815d32
Checked and Unchecked Exceptions in Java | by Ahmed Safwat | Medium
August 12, 2023 - Because unchecked exceptions typically indicate issues that should be fixed during development, they can often be avoided through proper coding practices, such as input validation and defensive programming. When working with exceptions in Java, it’s important to follow some best practices to ensure the maintainability and reliability of your code:
🌐
Oracle
docs.oracle.com › javase › tutorial › essential › exceptions › runtime.html
Unchecked Exceptions — The Controversy (The Java™ Tutorials > Essential Java Classes > Exceptions)
One case where it is common practice to throw a RuntimeException is when the user calls a method incorrectly. For example, a method can check if one of its arguments is incorrectly null. If an argument is null, the method might throw a NullPointerException, which is an unchecked exception.
🌐
Baeldung
baeldung.com › home › java › checked and unchecked exceptions in java
Checked and Unchecked Exceptions in Java | Baeldung
January 8, 2024 - The Oracle Java Documentation provides guidance on when to use checked exceptions and unchecked exceptions: “If a client can reasonably be expected to recover from an exception, make it a checked exception. If a client cannot do anything to recover from the exception, make it an unchecked exception.” · For example, before we open a file, we can first validate the input file name.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-checked-vs-unchecked-exceptions
Java Checked vs Unchecked Exceptions - GeeksforGeeks
October 2, 2025 - Partially Checked Exception: A checked exception where some of its child classes are unchecked (e.g., Exception). Checked exceptions represent invalid conditions in areas outside the immediate control of the program like memory, network, file system, etc. Any checked exception is a subclass of Exception. ... import java.io.*; class Geeks { public static void main(String[] args) { // Getting the current root directory String root = System.getProperty("user.dir"); System.out.println("Current root directory: " + root); // Adding the file name to the root directory String path = root + "\\message.
🌐
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 - Document the Exceptions: If your method can throw an unchecked exception, document this behavior in the method’s Javadoc to inform other developers. Here is a simple example of an unchecked exception (NullPointerException) and how it might occur:
🌐
TheServerSide
theserverside.com › answer › What-are-checked-vs-unchecked-exceptions-in-Java
What are checked vs. unchecked exceptions in Java? | TheServerSide
If try-and-catch semantics are not required, it is known as an unchecked exception. A checked exception in Java represents a predictable, erroneous situation that can occur even if a software library is used as intended. For example, if a developer tries to access a file, the Java IO library forces them to deal with the checked FileNotFoundException.
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.

🌐
DataFlair
data-flair.training › blogs › java-exception
Java Exception - Explore Checked & Unchecked Exception With Examples - DataFlair
November 6, 2024 - 2. Unchecked Exception in Java: The exception classes inheriting the RuntimeException class are unchecked exceptions. They are not checked at compilation time but during runtime. For example: ArithmeticException, IndexOutOfBOundException, etc.
Find elsewhere
🌐
Coding Shuttle
codingshuttle.com › java-programming-handbook › checked-and-unchecked-exceptions
Checked vs Unchecked Exceptions in Java: Ultimate Guide | Coding Shuttle
July 24, 2025 - public class UncheckedExceptionExample { public static void main(String[] args) { int a = 10, b = 0; int result = a / b; // This will throw ArithmeticException System.out.println("Result: " + result); } } Exception in thread "main" java.lang.ArithmeticException: / by zero at UncheckedExceptionExample.main(UncheckedExceptionExample.java:4)
🌐
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 - The code in the given program does not give any compile-time error. But when we run the example, it throws NullPointerException. NullPointerException is an unchecked exception in Java.
🌐
Scaler
scaler.com › topics › unchecked-exception-in-java
What Is an Unchecked Exception in Java? - Scaler Topics
October 7, 2022 - In this example, instead of passing an int value for the age, the string value is passed. This caused an exception. ... If a developer does not want the error to be solved (considering it does not crash the system) then unchecked exceptions should be used. It is used for caching the checked ...
🌐
Rollbar
rollbar.com › home › how to handle checked & unchecked exceptions in java
How to Handle Checked & Unchecked Exceptions in Java | Rollbar
July 5, 2024 - Unchecked exceptions are like running out of gas or getting a flat tire. These are things that could happen due to your own oversight. You're not legally required to constantly check your fuel gauge or tire pressure, but if these problems occur, ...
🌐
BeginnersBook -
beginnersbook.com › home › java › checked and unchecked exceptions in java with examples
Checked and unchecked exceptions in java with examples
October 25, 2022 - Or Unchecked Exception can be handled only with try-catch blocks. ... Hi, you have mentioned that DataAccessException is a checked exception. However it is a runtime exception and that’s what makes it different from SQLException. ... Excellent explanations and Examples used, in few seconds got everything.
🌐
Scientech Easy
scientecheasy.com › home › blog › checked and unchecked exceptions in java
Checked and Unchecked Exceptions in Java - Scientech Easy
April 30, 2025 - 3. Examples of checked exceptions are IOException, SQLException, ClassNotFoundException, etc whereas, examples of unchecked exceptions are ArithmeticException, ClassCastException, NullPointerException, IllegalArgumentException, etc.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-program-to-handle-unchecked-exception
Java Program to Handle Unchecked Exception - GeeksforGeeks
July 23, 2025 - Parent actions that helped him though he checked those stuffs but if someday somehow missed and the employee gets things correctly at home itself is referred as 'checked exception' in Java. The actions over which parental access does not have any control is referred as 'unchecked exceptions.'
🌐
BYJUS
byjus.com › gate › difference-between-checked-and-unchecked-exceptions-in-java
Differences between Checked and Unchecked Exceptions ...
September 28, 2022 - An exception in Java is a spontaneous event that occurs during the runtime that can interrupt the regular flow of the program. There are two types of exceptions: ... A checked exception is an exception that should be reported in the method in which it is thrown. ... An exception that occurs at the runtime or at the time of execution is known as an unchecked ...
🌐
Scaler
scaler.com › topics › checked-and-unchecked-exception-in-java
Checked and Unchecked Exception in Java - Scaler Topics
December 16, 2021 - Consider the example given below. ... When we try to compile the above code, the java compiler will throw a ParseException which occurs during the compilation time of the java program. The reason behind this is that we used the wrong format of date which causes an error and throws parse Exception. Runtime Exceptions are known as unchecked exceptions.
🌐
TechVidvan
techvidvan.com › tutorials › java-checked-and-unchecked-exception
Checked and Unchecked Exception in Java - Examples and Differences - TechVidvan
April 14, 2020 - According to the Oracle Java Documentation, there is a guide on when to use checked exceptions and unchecked exceptions: “If a client can reasonably be expected to recover from an exception, make it a checked exception. If a client cannot do anything to recover from the exception, make it an unchecked exception.” · For example, we can first validate the input file name before opening the file.
🌐
Java Mex
javamex.com › tutorials › exceptions › exceptions_unchecked.shtml
Unchecked exceptions in Java
They they don't have to be explicitly caught. When an unchecked exception occurs, such as a NullPointerException, ClassCastException, OutOfMemoryError etc, Java will "handle" the exception automatically (see below).
🌐
Javatpoint
javatpoint.com › exception-handling-in-java
Exception Handling in Java
Exception Handling in Java or Java Exceptions with checked, unchecked and errors with example and usage of try, catch, throw, throws and finally keywords.