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 - In Java, there are two types of ... to handle them explicitly. Unchecked Exception: These exceptions are checked at runtime and do not require explicit handling at compile time....
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.

Discussions

Exceptions - Checked vs Unchecked
There's a good article series on this at programming.guide. Difference between checked and unchecked exceptions explains the difference, with examples. Basically, checked exceptions are all those exceptions extending Exception (except RuntimeException and its subclasses.) Once you got that down, you'd probably want to read Choosing between checked and unchecked exceptions . Spoiler alert: Only under very specific circumstances would you want to go for a checked one. And, if you feel like really understanding the pro's and con's and the debate of whether checked exceptions is a good idea to begin with, check out https://programming.guide/java/checked-exceptions-good-or-bad.html . More on reddit.com
๐ŸŒ r/learnjava
3
3
April 29, 2020
java - Is it good practice to catch a checked exception and throw a RuntimeException? - Software Engineering Stack Exchange
It's interesting to note that Jim Waldo rants against unchecked exceptions in "Java: The Good Parts" shop.oreilly.com/product/9780596803742.do saying that adult programmers should only throw checked exceptions. We read it in our JUG only 6 years ago when it came out and it seemed like good advice! More on softwareengineering.stackexchange.com
๐ŸŒ softwareengineering.stackexchange.com
November 23, 2011
What do you think about removing checked exceptions in kotlin?
Java's checked exceptions are widely regarded as a mistake. Even in Java, many common libraries choose for their exceptions to subclass RuntimeException to avoid the pain. Hibernate does this for example. Some of it is bad API design. For example, for a long time, Java's reflection APIs threw an assortment of exceptions with no shared superclass. But this ultimately points to a more general problem, that the bigger your system gets, the more ways it can fail, and at some point there are so many failure modes that it makes no sense to try and enumerate them. At which point you just mark your methods as throws Exception, which gives you no more information about possible failures than unchecked exceptions would. But the real kicker is that if you want to implement an interface that doesn't throw, and you want to implement it using a method that does, you've got no good options. If you redefine the interface to throw your exception (which may not even be possible) then implementation detail has leaked into the interface definition. And if you don't, then the best you can do is wrap your exception in a different exception that doesn't give callers enough info about what went wrong to do anything about it, which adds boilerplate but not value. More on reddit.com
๐ŸŒ r/Kotlin
103
34
September 23, 2023
Unchecked Java: Say Goodbye to Checked Exceptions Forever
really, after 20 more years of Java, I don't understand what's wrong with checked exceptions ๐Ÿ˜ฌ๐Ÿ˜„ it's that annoying to catch them? More on reddit.com
๐ŸŒ r/java
72
54
July 13, 2023
๐ŸŒ
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 ... 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 ...
๐ŸŒ
Yegor256
yegor256.com โ€บ 2015 โ€บ 07 โ€บ 28 โ€บ checked-vs-unchecked-exceptions.html
Checked vs. Unchecked Exceptions: The Debate Is Not Over
July 28, 2015 - Thatโ€™s why we always have to catch everything inside the method and rethrow checked exceptions as unchecked. If all methods in all Java interfaces would be declared either as โ€œsafeโ€ (throws nothing) or โ€œunsafeโ€ (throws Exception), everything would become logical and clear.
๐ŸŒ
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?

๐ŸŒ
Oracle
docs.oracle.com โ€บ javase โ€บ tutorial โ€บ essential โ€บ exceptions โ€บ runtime.html
Unchecked Exceptions ย— The Controversy (The Javaโ„ข Tutorials > Essential Java Classes > Exceptions)
Here's the bottom line guideline: 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.
๐ŸŒ
Quora
quora.com โ€บ How-does-Java-consider-RuntimeException-as-unchecked-while-its-superclass-Exception-is-considered-checked
How does Java consider RuntimeException as unchecked while its superclass Exception is considered checked? - Quora
Answer (1 of 4): There actually three kinds of throwables in Java: 1. subclasses of Exception, which are checked, except for 2. subclasses of RuntimeException, which are unchecked; 3. subclasses of Error, which are also unchecked As someone earlier pointed out, enforcing the rules around checke...
Find elsewhere
๐ŸŒ
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, ...
๐ŸŒ
Scaler
scaler.com โ€บ topics โ€บ unchecked-exception-in-java
What Is an Unchecked Exception in Java? - Scaler Topics
October 7, 2022 - In Java, exceptions that are under Error and , Runtime exception classes are unchecked exceptions.
๐ŸŒ
Medium
medium.com โ€บ @devcorner โ€บ unchecked-exceptions-in-java-to-handle-or-not-to-handle-bd617efad76c
Unchecked Exceptions in Java: To Handle or Not to Handle? ๐Ÿค” | by Dev Corner | Medium
November 29, 2024 - Unchecked exceptions in Java are a subclass of RuntimeException. Unlike checked exceptions, they do not need to be declared in the throws clause or wrapped in try-catch blocks.
Top answer
1 of 13
60

I do not know enough context to know whether your colleague is doing something incorrectly or not, so I am going to argue about this in a general sense.

I do not think it is always an incorrect practice to turn checked exceptions into some flavor of runtime exception. Checked exceptions are often misused and abused by developers.

It is very easy to use checked exceptions when they are not meant to be used (unrecoverable conditions, or even control flow). Especially if a checked exception is used for conditions from which the caller cannot recover, I think it is justified to turn that exception to a runtime exception with a helpful message/state. Unfortunately in many cases when one is faced with an unrecoverable condition, they tend to have an empty catch block which is one of the worst things you can do. Debugging such an issue is one of the biggest pains a developer can encounter.

So if you think that you are dealing with a recoverable condition, it should be handled accordingly and the exception should not be turned into a runtime exception. If a checked exception is used for unrecoverable conditions, turning it into a runtime exception is justified.

2 of 13
47

It can be GOOD. Please read this onjava.com article:

Most of the time, client code cannot do anything about SQLExceptions. Do not hesitate to convert them into unchecked exceptions. Consider the following piece of code:

public void dataAccessCode(){
  try{
      ..some code that throws SQLException
  }catch(SQLException ex){
      ex.printStacktrace();
  }
} 

This catch block just suppresses the exception and does nothing. The justification is that there is nothing my client could do about an SQLException. How about dealing with it in the following manner?

public void dataAccessCode(){
   try{
       ..some code that throws SQLException
   }catch(SQLException ex){
       throw new RuntimeException(ex);
   }
} 

This converts SQLException to RuntimeException. If SQLException occurs, the catch clause throws a new RuntimeException. The execution thread is suspended and the exception gets reported. However, I am not corrupting my business object layer with unnecessary exception handling, especially since it cannot do anything about an SQLException. If my catch needs the root exception cause, I can make use of the getCause() method available in all exception classes as of JDK1.4.

Throwing checked exceptions and not being able to recover from it is not helping.

Some people even think that checked exceptions should not be used at all. See http://www.ibm.com/developerworks/java/library/j-jtp05254/index.html

Recently, several well-regarded experts, including Bruce Eckel and Rod Johnson, have publicly stated that while they initially agreed completely with the orthodox position on checked exceptions, they've concluded that exclusive use of checked exceptions is not as good an idea as it appeared at first, and that checked exceptions have become a significant source of problems for many large projects. Eckel takes a more extreme view, suggesting that all exceptions should be unchecked; Johnson's view is more conservative, but still suggests that the orthodox preference for checked exceptions is excessive. (It's worth noting that the architects of C#, who almost certainly had plenty of experience using Java technology, chose to omit checked exceptions from the language design, making all exceptions unchecked exceptions. They did, however, leave room for an implementation of checked exceptions at a later time.)

Also from the same link:

The decision to use unchecked exceptions is a complicated one, and it's clear that there's no obvious answer. The Sun advice is to use them for nothing, the C# approach (which Eckel and others agree with) is to use them for everything. Others say, "there's a middle ground."

๐ŸŒ
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. - Purpose: Checked exceptions are generally used for r...
๐ŸŒ
Wikibooks
en.wikibooks.org โ€บ wiki โ€บ Java_Programming โ€บ Unchecked_Exceptions
Unchecked Exceptions - Wikibooks, open books for an open world
August 18, 2006 - Java Programming ยท Unchecked, uncaught or runtime exceptions are exceptions that can be thrown without being caught or declared: ...however, you can still declare and catch such exceptions. Runtime exceptions are not business exceptions. They are usually related to hard-coded issues like data ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ exceptions-in-java
Java Exception Handling - GeeksforGeeks
Checked Exception: These exceptions are checked at compile time, forcing the programmer to handle them explicitly. Unchecked Exception: These exceptions are checked at runtime and do not require explicit handling at compile time.
Published ย  1 month ago
๐ŸŒ
CodeJava
codejava.net โ€บ java-core โ€บ exception โ€บ java-checked-and-unchecked-exceptions
Java Checked and Unchecked Exceptions
February 10, 2025 - List<String> list = new ArrayList<>(); String item = list.get(3);The get() method of the ArrayList class can throw IndexOutOfBoundsException but the code doesnโ€™t have to catch because it is an unchecked exception.See common unchecked exceptions in the section 4 below. Common checked exceptions defined in the java.lang package:
๐ŸŒ
Coding Shuttle
codingshuttle.com โ€บ java-programming-handbook โ€บ checked-and-unchecked-exceptions
Checked vs Unchecked Exceptions in Java: Ultimate Guide | Coding Shuttle
July 24, 2025 - Unchecked Exceptions โ€“ Exceptions that occur at runtime and do not require mandatory handling. ... Checked exceptions are exceptions that must be handled using a try-catch block or declared using throws in the method signature.
๐ŸŒ
TheServerSide
theserverside.com โ€บ answer โ€บ What-are-checked-vs-unchecked-exceptions-in-Java
What are checked vs. unchecked exceptions in Java? | TheServerSide
In contrast to a checked exception, an unchecked exception represents an error in programming logic, not an erroneous situation that might reasonably occur during the proper use of an API.
Published ย  April 18, 2022
๐ŸŒ
Studyeasy
studyeasy.org โ€บ course-articles โ€บ java-en-en โ€บ s07l34-checked-and-unchecked-exception-in-java
S07L34 โ€“ Checked and unchecked exception in Java โ€“ Studyeasy
In this eBook, we will delve into the intricacies of checked and unchecked exceptions, exploring their definitions, differences, use cases, and best practices. 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 either handled using a try-catch block or declared in the method signature using the throws keyword.
๐ŸŒ
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:
๐ŸŒ
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).