🌐
GeeksforGeeks
geeksforgeeks.org › java › types-of-exception-in-java-with-examples
Types of Exception in Java with Examples - GeeksforGeeks
July 23, 2025 - ArithmeticException: It is thrown when an exceptional condition has occurred in an arithmetic operation. ArrayIndexOutOfBoundsException: It is thrown to indicate that an array has been accessed with an illegal index.
🌐
W3Schools
w3schools.com › java › java_ref_errors.asp
Java Error and Exception Types Reference
The table below shows a list of common Error and Exception types in Java: Java Errors Tutorial · Java Exception Handling Tutorial · ❮ Previous Next ❯ · ★ +1 · Sign in to track progress · REMOVE ADS · PLUS · SPACES · GET CERTIFIED · FOR TEACHERS ·
Discussions

Exception Handling in Java: A Complete Guide with Best and Worst Practices
Paging u/davidlandup In the logging and throwing section, it's probably worth mentioning that sometimes you want to add extra context to your situation, in which case it's a good idea to wrap the exception in a custom exception with that information. I'd also mention that because exceptions are just Java classes, you can create custom fields inside them to record all the required information. For example, if you have a AccessDeniedException you could create a constructor that takes a username and name of the resource they tried to access, as well as any additional message. More on reddit.com
🌐 r/java
6
18
September 17, 2018
Exception handling in Java: Advanced features and types
The article has some errors. And not the throwable kind, heh: If not found, it unwinds the method-call stack looking for the closest catch block that can handle the exception. If not found, the JVM terminates with a suitable message. You can see this action in Listing 1. The part in italics is incorrect! What happens if there is no catch block that is suitable is that the thread exits and passes the exception that was never caught to the thread's uncaught exception handler. And that's that. The thread is done. By default, each thread starts with an uncaught exception handler that simply prints the exception to syserr (e.printStackTrace(); - that's the whole body, that's all). At no point does it ever exit a JVM. Of course, if you have a java app that never starts any threads, then the main thread is the only relevant thread, and if that exits due to an exception bubbling all the way up, yeah, sure, the JVM then exits as no non-daemon threads are running. But it feels ridiculous to handwave this away as 'oh we are just trying to keep it simple'. "The thread dies" is just as simple and much more accurate. You can invoke printStackTrace() directly, typically from a catch block. For example, consider a second version of the PrintStackTraceDemo application. This entire article keeps making pointless and misleading sidenotes. For example, it sidenotes 'you can also call printStackTrace(somePrintWriter) which is weird to mention; anybody can look at the API docs and discover this, and it's not like they're covering the entire API here. It's like I'm pointing out all the interesting aspects of the Mona Lisa and then casually remark: "Oh, look, someone dropped a candy wrapper over there. Anyway, moving right along..." - it's just bizarre to mention this. It strongly insinuates that this is important. And that then blows up thoroughly in the quoted section: Newbies are legendary in writing catch blocks with e.printStackTrace(); in it which is a massive anti-pattern that is difficult to eradicate. And this blog post is making it worse by using it as a way to explain that you can invoke printStackTrace yourself (not an important lesson!) without explaining that you shouldn't do that or that this contrived example shouldn't be taken as an insinuation of: "Ah, and this is how you write your standard catch block". Try-with-resources Another example that is fucking horrible. You don't deal with IOExceptions thrown by close() methods by ignoring them!! streams buffer. Any exception thrown by a close() method means the entire write operation has likely failed. If you treat them differently than any exception that would have been thrown by the most recent write call you wrote a hard-to-test for bug (i.e: A really really bad bug). But that isn't obvious here. It's again teaching extremely bad patterns. Listing 8. Copy.java No, the right way to deal with exceptions thrown here is to just declare your main method as throws Exception which you should almost always do. Writing a catch block that tosses most of the useful info in the garbage (as in this snippet, the exception's type which might be FileAccessDeniedException or whatnot - the key info, you toss that away!), then just writes something and blindly continues with the app is ON ERROR RESUME NEXT level stupidity. Common stupidity, but that shouldn't be an excuse. On the contrary, given that the common-ness has proven that your average new java programmer will readily misunderstand, you should go out of your way not to perpetuate this mistake. As is, this article should be torched with a flamethrower: If you send this to new java programmers and they read it, they'll be stupider after having read it than before. The article is fixable though. Come up with less 'actively perpetuating really stupid anti-patterns' examples, stop trying to be opinion-less (because the chosen examples and focus invoke an opinion, whether you intended it or not, and right now it's invoking the wrong ones), and cut some of the irrelevant chaff such as how to make your own stack trace (not relevant for an intro article in any way and actively misleads in suggesting that it is somehow an important tool one should be using often) and mentioning irrelevant parts of the API. More on reddit.com
🌐 r/java
9
17
May 28, 2024
Exception Handling Guide in Java
Devs are just too lazy to think about proper error handling. They just don't like the look of "verbose" throws and try-catches. There I called it. Checked exceptions are a nice instrument for situations where you have a recoverable business error and no result object to integrate the error into. Anyway, be it runtime exception or checked exception or result object or Either or Try, a business error must be part of the API. They are not an abstraction leak. Runtime exception is the only one of the mentioned above that can be - and often is - made invisible to the caller. More on reddit.com
🌐 r/java
45
30
January 24, 2021
Handling Checked Exceptions in Java Functional Interfaces (Lambdas)
Usually I either have ugly inline try catch blocks, a private method doing the same, or I make sure the method I call only uses unchecked exceptions - but it’s not ideal and and unfortunately a posterbook example of Java's design. More on reddit.com
🌐 r/java
78
39
September 23, 2024
🌐
Stackify
stackify.com › types-of-exceptions-java
Types of Exceptions in Java - Stackify
March 14, 2024 - There are mainly two types of exceptions in Java as follows: ... Checked exceptions are also known as compile-time exceptions as these exceptions are checked by the compiler during the compilation process to confirm whether the exception is ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › exceptions-in-java
Java Exception Handling - GeeksforGeeks
Exception caught: java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 3 This block always executes. Program continues... 1. throw: Used to explicitly throw a single exception. We use throw when something goes wrong (or “shouldn’t happen”) and we want to stop normal flow and hand control to exception handling.
Published   1 month ago
🌐
Tutorialspoint
tutorialspoint.com › java › java_exceptions.htm
Java - Exceptions
Try to understand the difference between throws and throw keywords, throws is used to postpone the handling of a checked exception and throw is used to invoke an exception explicitly. The following method declares that it throws a RemoteException − · import java.io.*; public class className { public void deposit(double amount) throws RemoteException { // Method implementation throw new RemoteException(); } // Remainder of class definition }
🌐
Medium
medium.com › @ShantKhayalian › mastering-java-exception-handling-a-comprehensive-guide-for-developers-c31cef921d75
Mastering Java Exception Handling: A Comprehensive Guide for Developers | by Balian's techologies and innovation lab | Medium
June 17, 2024 - Errors are subclasses of Error and usually indicate problems that the application cannot recover from. ... Java provides a structured way to handle exceptions using five key keywords: try, catch, finally, throw, and throws.
🌐
Quora
quora.com › What-are-the-types-of-exceptions-in-Java
What are the types of exceptions in Java? - Quora
It is an object which is thrown at runtime. Types of Exception There are mainly two types of exceptions: checked and unchecked where error is considered as unchecked exception. The sun microsystem say...
🌐
Educative
educative.io › answers › what-are-different-types-of-exceptions-in-java
What are different types of exceptions in Java?
If a method throws a checked exception, then the caller of the method must either handle the exception or declare it in the throws clause. Unchecked exceptions: These are the exceptions that are not checked by the compiler at compile time. They include runtime exceptions and errors. The exception class hierarchy in Java is as follows:
Find elsewhere
🌐
Raygun
raygun.com › blog › java-exceptions-terminology
Java exceptions: Common terminology with examples · Raygun Blog
October 25, 2022 - For example, IOException is a subclass of Exception and NullPointerException is a subclass of RuntimeException. You may have noticed that Java differentiates errors from exceptions. ... In Java, errors indicate abnormal conditions such as stack overflow that applications shouldn’t try to catch. They are mostly caused by the environment, as opposed to exceptions that are caused by the program itself. Exceptions are caught either at compile time or at runtime. Errors terminate the program for sure and they cannot be handled in any way.
🌐
LinkedIn
linkedin.com › pulse › java-exception-handling-part-i-exceptions-its-types-alphadot-tech
Java Exception Handling - Part I (Exceptions and its types)
August 17, 2023 - An exception normally disrupts the normal flow of the application, thus we need to handle it. ... There are mainly two types of exceptions: checked and unchecked. An error is considered as unchecked exception.
🌐
Oracle
docs.oracle.com › javase › tutorial › essential › exceptions › index.html
Lesson: Exceptions (The Java™ Tutorials > Essential Java Classes)
This section explains the correct and incorrect use of the unchecked exceptions indicated by subclasses of RuntimeException.
🌐
LambdaTest
lambdatest.com › home › blog › what is exception handling: types and best practices
What Is Exception Handling: Types and Best Practices | LambdaTest
January 23, 2025 - Exception: This branch includes conditions that programs can handle, such as IOException, which occurs when there is an issue with input or output operations. Error: This branch represents critical issues related to the Java runtime environment, like OutOfMemoryError, which occurs when the JVM runs out of memory to allocate objects. Below is the hierarchy of Java’s exception classes: In Java, exceptions are broadly categorized into two types:
🌐
Sentry
blog.sentry.io › exception-handling-in-java-with-real-examples
Exception Handling in Java (with Real Examples) | Product Blog • Sentry
July 15, 2025 - What types of exceptions exist in Java, and how are they classified? Java exceptions are broadly categorized into checked and unchecked exceptions. Checked exceptions are detected during compilation, while unchecked exceptions occur at runtime.
🌐
Scaler
scaler.com › topics › types-of-exception-in-java
Types of Exception in Java - Scaler Topics
November 7, 2022 - An example of a built-in exception can be ArithmeticException; it is a pre-defined exception in the Exception class of java.lang package. These can be further divided into two types: ... Checked exceptions are caught at compile time, indicating potentially recoverable errors. The compiler enforces handling them before runtime.
🌐
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). Exception handling lets you catch and handle errors during runtime - so your program doesn't crash.
🌐
BeginnersBook -
beginnersbook.com › home › java › exception handling in java with examples
Exception handling in Java with examples
October 25, 2022 - There are two types of exceptions in Java: 1) Checked exceptions 2) Unchecked exceptions · I have covered these topics in detail in a separate tutorial: Checked and Unchecked exceptions in Java. All exceptions other than Runtime Exceptions are known as Checked exceptions as the compiler checks ...
🌐
j-labs
j-labs.pl › home › tech blog › java exception handling: strategies and best practices
Java Exception Handling in Java Best Practices | j‑labs
October 9, 2025 - Java’s exception handling mechanism ... categorized into three main types based on their origin and behavior: checked exceptions, unchecked exceptions, and errors....
🌐
Vlabs
java-iitd.vlabs.ac.in › exp › exceptions › theory.html
Exception Handling in Java - Virtual Labs
In Java, an exception is an event that disrupts the normal flow of the program. It is an object which is thrown at runtime. Exception Handling is a mechanism to handle runtime errors such a ClassNotFoundException, IOException, SQLException, RemoteException, etc.
🌐
Oracle
docs.oracle.com › javase › specs › jls › se16 › html › jls-11.html
Chapter 11. Exceptions
September 16, 2025 - Programs can use the pre-existing exception classes of the Java SE Platform API in throw statements, or define additional exception classes as subclasses of Throwable or of any of its subclasses, as appropriate. 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.
🌐
Rollbar
rollbar.com › home › java exceptions hierarchy explained
Java Exceptions Hierarchy Explained | Rollbar
May 15, 2025 - Exception in thread "main" java.lang.NullPointerException at IOExceptionExample.writeToFile(IOExceptionExample.java:10) at IOExceptionExample.main(IOExceptionExample.java:17) As mentioned, since NullPointerException is an unchecked exception, it did not need to be handled in code - only the checked exception (IOException) was handled. While understanding the exception hierarchy is important, how you use exceptions in your code matters even more. Consider these key practices: Be specific with exception types - catch the most specific exception possible rather than using catch-all blocks