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
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-checked-vs-unchecked-exceptions
Java Checked vs Unchecked Exceptions - GeeksforGeeks
October 2, 2025 - Fully Checked Exception: A checked exception where all its child classes are also checked (e.g., IOException, InterruptedException). Partially Checked Exception: A checked exception where some of its child classes are unchecked (e.g., Exception).
🌐
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 - Checked Exceptions: Encourage error handling and robustness in applications by making exception handling mandatory. Unchecked Exceptions: Encourage developers to fix the underlying programming errors and use exception handling only for truly exceptional conditions that the application cannot anticipate or recover from. Understanding the difference between checked and unchecked exceptions is essential for Java developers.
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.

🌐
Rollbar
rollbar.com › home › how to handle checked & unchecked exceptions in java
How to Handle Checked & Unchecked Exceptions in Java | Rollbar
July 5, 2024 - A checked exception is caught at compile time whereas a runtime or unchecked exception is, as it states, at runtime. A checked exception must be handled either by re-throwing or with a try catch block, whereas a runtime isn’t required to be ...
🌐
Baeldung
baeldung.com › home › java › checked and unchecked exceptions in java
Checked and Unchecked Exceptions in Java | Baeldung
January 8, 2024 - 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.”
🌐
BYJUS
byjus.com › gate › difference-between-checked-and-unchecked-exceptions-in-java
Differences between Checked and Unchecked Exceptions ...
September 28, 2022 - 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 exception.
🌐
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 – Exceptions that must be handled at compile time. Unchecked Exceptions – Exceptions that occur at runtime and do not require mandatory handling.
🌐
Reddit
reddit.com › r/learnjava › exceptions - checked vs unchecked
r/learnjava on Reddit: Exceptions - Checked vs Unchecked
April 29, 2020 -

A checked exception required a throw clause on the method header but not for the unchecked exception?

What is the difference between the two? How do I know if it is unchecked vs checked?

Find elsewhere
🌐
TheServerSide
theserverside.com › answer › What-are-checked-vs-unchecked-exceptions-in-Java
What are checked vs. unchecked exceptions in Java? | TheServerSide
When an exception must be handled with try-and-catch semantics, it is known as a checked exceptions. If try-and-catch semantics are not required, it is known as an unchecked exception.
🌐
W3Schools
w3schools.in › java › questions-answers › difference-between-checked-and-unchecked-exceptions-in-java
Difference Between Checked and Unchecked Exceptions in Java
In Java programming, for every occurrence of an exception, there generates an exception object, which holds all the details of the exception. Then the program searches for its respective exception handler. If found, the exception is handled or resolved, or else the program execution stops.
🌐
Sololearn
sololearn.com › en › Discuss › 1403027 › what-is-the-exact-difference-between-checked-and-unchecked-exceptions
What is the exact difference between checked and unchecked exceptions? | Sololearn: Learn to code for FREE!
Unchecked exceptions return errors and end the program. The code finds something wonky and get confused so stops. Checked exceptions tell the code: there is a possibility this wonkiness may happen, so look out for it.
🌐
TutorialsPoint
tutorialspoint.com › difference-between-checked-and-unchecked-exception-in-java
Difference Between Checked and Unchecked Exception in Java
The compiler doesn’t check for these kinds of exceptions. These kinds of exceptions can’t be caught or handled during compilation time. This is because the exceptions are generated due to the mistakes in the program. These are not a part of the ‘Exception’ class since they are runtime exceptions. The JVM doesn’t require the exception to be caught and handled. Example of Unchecked Exceptions- ‘No Such Element Exception’
🌐
Yegor256
yegor256.com › 2015 › 07 › 28 › checked-vs-unchecked-exceptions.html
Checked vs. Unchecked Exceptions: The Debate Is Not Over
When a method is too big and does ... does all of us more harm than good—methods keep growing in size and complexity. Unchecked exceptions are a mistake in Java design, not checked ones....
🌐
DEV Community
dev.to › realnamehidden1_61 › whats-the-difference-between-checked-exception-and-unchecked-exception-in-java-977
⚠️ What’s the Difference Between Checked Exception and Unchecked Exception in Java? - DEV Community
October 23, 2025 - In Java programming, checked exceptions prepare you for known issues at compile-time, while unchecked exceptions handle unexpected runtime errors. Understanding their difference helps you decide when to anticipate errors and when to fix logic flaws.
Top answer
1 of 16
321

Checked Exceptions are great, so long as you understand when they should be used. The Java core API fails to follow these rules for SQLException (and sometimes for IOException) which is why they are so terrible.

Checked Exceptions should be used for predictable, but unpreventable errors that are reasonable to recover from.

Unchecked Exceptions should be used for everything else.

I'll break this down for you, because most people misunderstand what this means.

  1. Predictable but unpreventable: The caller did everything within their power to validate the input parameters, but some condition outside their control has caused the operation to fail. For example, you try reading a file but someone deletes it between the time you check if it exists and the time the read operation begins. By declaring a checked exception, you are telling the caller to anticipate this failure.
  2. Reasonable to recover from: There is no point telling callers to anticipate exceptions that they cannot recover from. If a user attempts to read from an non-existing file, the caller can prompt them for a new filename. On the other hand, if the method fails due to a programming bug (invalid method arguments or buggy method implementation) there is nothing the application can do to fix the problem in mid-execution. The best it can do is log the problem and wait for the developer to fix it at a later time.

Unless the exception you are throwing meets all of the above conditions it should use an Unchecked Exception.

Reevaluate at every level: Sometimes the method catching the checked exception isn't the right place to handle the error. In that case, consider what is reasonable for your own callers. If the exception is predictable, unpreventable and reasonable for them to recover from then you should throw a checked exception yourself. If not, you should wrap the exception in an unchecked exception. If you follow this rule you will find yourself converting checked exceptions to unchecked exceptions and vice versa depending on what layer you are in.

For both checked and unchecked exceptions, use the right abstraction level. For example, a code repository with two different implementations (database and filesystem) should avoid exposing implementation-specific details by throwing SQLException or IOException. Instead, it should wrap the exception in an abstraction that spans all implementations (e.g. RepositoryException).

2 of 16
65

From A Java Learner:

When an exception occurs, you have to either catch and handle the exception, or tell compiler that you can't handle it by declaring that your method throws that exception, then the code that uses your method will have to handle that exception (even it also may choose to declare that it throws the exception if it can't handle it).

Compiler will check that we have done one of the two things (catch, or declare). So these are called Checked exceptions. But Errors, and Runtime Exceptions are not checked for by compiler (even though you can choose to catch, or declare, it is not required). So, these two are called Unchecked exceptions.

Errors are used to represent those conditions which occur outside the application, such as crash of the system. Runtime exceptions are usually occur by fault in the application logic. You can't do anything in these situations. When runtime exception occur, you have to re-write your program code. So, these are not checked by compiler. These runtime exceptions will uncover in development, and testing period. Then we have to refactor our code to remove these errors.

🌐
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 - Remember, the biggest difference between checked and unchecked exceptions is that checked exceptions are forced by the compiler and used to indicate exceptional conditions that are out of the program’s control, while unchecked exceptions occur during runtime and are used to indicate programming errors.
Top answer
1 of 8
30

Unchecked exceptions are those that extend RuntimeException class. Compiler will never force you to catch such exception or force you to declare it in the method using throws keyword. All other exception types (that do not extend RuntimeException) are checked and therefore must be declared to be thrown and/or catched.

Checked exceptions are used when you want the caller of your method (i.e the user of your API) to explicitly handle the exceptional case in your API. Checked exceptions are declared when you believe the call will be able to do something meaningful with that exceptional case, like retrying the call, rolling changes back or converting it into some user-readable error message.

If you believe that there is nothing useful the call can do about the exception (especially when it represents a bug, or a wrong usage of your API), then the exception should be unchecked. Also, an API with too many checked exceptions can be annoying to program with (e.g. try using java reflection API=)

2 of 8
11
  • Checked Exceptions are useful for handling events that occur in the normal operation of a program. An example would be an IOException that is thrown when a file cannot be opened. These exceptions occur even if there is nothing wrong with the program. It is necessary, therefore, to tell the program how to handle the exception.
  • Unchecked exceptions are useful for identifying defects in the code. For instance, a NullPointerException is thrown when a value is read on a null object. Thus an Unchecked Exception represents a problem that requires a manual fix by the programmer. It is reasonable for the program to crash in order to avoid erroneous behavior, so a try-catch block is not required (but might be desirable in order to provide mitigation, such as displaying an error to the user).
🌐
Testbook
testbook.com › home › key differences › differences between checked and unchecked exceptions in java
Differences between Checked and Unchecked Exceptions in Java
A checked exception is a type of exception that must be declared within the method where it is thrown. ... An unchecked exception is an exception that occurs during the execution or runtime of a program.
🌐
C# Corner
c-sharpcorner.com › UploadFile › 3614a6 › difference-between-checked-and-unchecked-exceptions-in-java
Difference Between Checked and Unchecked Exceptions in Java
July 22, 2019 - In Checked Exceptions the Java Virtual Machine requires the exception to be caught or handled, while in Unchecked Exceptions the Java Virtual Machine does not require the exception to be caught or handled.