🌐
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.
🌐
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 - If the exception reaches the program’s entry point (for example, the main method) and no suitable catch block is found, the exception is considered "uncaught." Uncaught exceptions are typically logged, and the program may terminate, displaying an error message along with the stack trace. Using checked exceptions allows you to enforce proper error handling and make it explicit which parts of your code can potentially throw exceptions.
🌐
TheServerSide
theserverside.com › answer › What-are-checked-vs-unchecked-exceptions-in-Java
What are checked vs. unchecked exceptions in Java? | TheServerSide
A checked exception in Java represents ... 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....
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-checked-vs-unchecked-exceptions
Java Checked vs Unchecked Exceptions - GeeksforGeeks
October 2, 2025 - If a method throws a checked Exception, then the exception must be handled using a try-catch block and declared the exception in the method signature using the throws keyword.
🌐
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 - Checked exceptions can be used when a method may fail to do what it must. For example, a method named prepareSystem() that pre-populates configuration files and does some configuration using them.
🌐
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 that exception and see if the API is back up and running the second time.
🌐
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
🌐
Wikibooks
en.wikibooks.org › wiki › Java_Programming › Checked_Exceptions
Checked Exceptions - Wikibooks, open books for an open world
A checked exception is a type of exception that must be either caught or declared in the method in which it is thrown. For example, the java.io.IOException is a checked 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 - Avoid Overusing Throws Clause: Do not declare too many exceptions in the throws clause of the method signature, as it can make your API difficult to use. Here’s an example demonstrating how to handle a common checked exception, IOException:
Find elsewhere
🌐
Oracle
docs.oracle.com › javase › tutorial › essential › exceptions › catchOrDeclare.html
The Catch or Specify Requirement (The Java™ Tutorials > Essential Java Classes > Exceptions)
The first kind of exception is ... should anticipate and recover from. For example, suppose an application prompts a user for an input file name, then opens the file by passing the name to the constructor for java.io.FileReader....
🌐
Oracle
docs.oracle.com › javase › specs › jls › se7 › html › jls-11.html
Chapter 11. Exceptions
September 16, 2025 - A Java compiler is encouraged to ... of E1, and a preceding catch clause of the immediately enclosing try statement can catch checked exception class E3 where E2 <: E3 <: E1. Example 11.2.3-1....
🌐
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.
🌐
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.
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.

🌐
BeginnersBook -
beginnersbook.com › home › java › checked and unchecked exceptions in java with examples
Checked and unchecked exceptions in java with examples
October 25, 2022 - In this program there are three places where a checked exception is thrown as mentioned in the comments below. FileInputStream which is used for specifying the file path and name, throws FileNotFoundException. The read() method which reads the file content throws IOException and the close() method which closes the file input stream also throws IOException. import java.io.*; class Example { public static void main(String args[]) { FileInputStream fis = null; /*This constructor FileInputStream(File filename) * throws FileNotFoundException which is a checked * exception */ fis = new FileInputStream("B:/myfile.txt"); int k; /* Method read() of FileInputStream class also throws * a checked exception: IOException */ while(( k = fis.read() ) != -1) { System.out.print((char)k); } /*The method close() closes the file input stream * It throws IOException*/ fis.close(); } }
🌐
Vonage
developer.vonage.com › en › blog › why-you-should-avoid-using-checked-exceptions-in-java
Why You Should Avoid Using Checked Exceptions in Java
However, new checked exceptions which are not declared by the super method cannot be thrown as this would violate the polymorphic principles that the language relies on. The semantics become easier to understand with the aid of a compiler, so if you are unfamiliar with exceptions in Java, I encourage you to play around with the code in your IDE. For example, notice how the compiler forces you to handle both CheckedA and CheckedB if you change the call from api.unchecked() to api.checked() in the following example, This is because you're calling the interface method, not the implementation one.
🌐
Scaler
scaler.com › topics › checked-exception-in-java
What Is Checked Exception in Java? - Scaler Topics
October 7, 2022 - The error can be SQL syntax or SQL driver. FileNotFoundException : It occurs when a file that we are trying to find is unavailable in the directory. It is available in class java.io and is a checked exception because it is thrown by the constructor RandomAccessFile at run time.
🌐
Javatpoint
javatpoint.com › list-of-checked-exceptions-in-java
List of Checked Exceptions in Java - Javatpoint
List of Checked Exceptions in Java with java tutorial, features, history, variables, programs, operators, oops concept, array, string, map, math, methods, examples etc.
🌐
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.
🌐
CodeJava
codejava.net › java-core › exception › java-checked-and-unchecked-exceptions
Java Checked and Unchecked Exceptions
The exceptions that are subtypes of Exception (exclude subtypes of RuntimeException) are categorized as checked exceptions. When we use code that can throw checked exceptions, we must handle them, otherwise the compiler will complain.For example, the following method can throw a checked exception of type IOException: