An exception is a problem that arises during the execution of a program. An exception can occur for many different reasons. Some of these exceptions are caused by user error, others by programmer error, and others by physical resources that have failed in some manner.
To understand how exception handling works in Java, you need to understand the three categories of exceptions:
Checked exceptions: A checked exception is an exception that is typically a user error or a problem that cannot be foreseen by the programmer. For example, if a file is to be opened, but the file cannot be found, an exception occurs. These exceptions cannot simply be ignored at the time of compilation.
Runtime exceptions: A runtime exception is an exception that occurs that probably could have been avoided by the programmer. As opposed to checked exceptions, runtime exceptions are ignored at the time of compilation.
Errors: These are not exceptions at all, but problems that arise beyond the control of the user or the programmer. Errors are typically ignored in your code because you can rarely do anything about an error. For example, if a stack overflow occurs, an error will arise. They are also ignored at the time of compilation.
Go through these tutorials to gain more insight.
Related Tags
Tutorials
java.lang.NoSuchMethodError means code compiled against one version of a class runs with another version that lacks the called method. Learn to read the message, find the wrong jar with mvn dependency:tree, -verbose:class and javap, and fix the conflict with a BOM, an exclusion and the Enforcer dependencyConvergence rule.
A StackOverflowError means a thread made more nested calls than its stack can hold. Learn to read the repeating stack trace, fix missing base cases, deep recursion and object cycles in toString(), Lombok and Jackson, and when -Xss helps.
IllegalArgumentException is the unchecked exception a Java method throws when an argument has a value it does not accept. This post lists the JDK calls that throw it with their real Java 25 messages and the fix for each, the subclasses such as NumberFormatException, and when our own code should throw it instead of IllegalStateException or NullPointerException.
“Unsupported class file major version 69” means a JVM or bytecode tool older than Java 25 tried to read a Java 25 class file. Learn to read the class file version, map it to the Java release, and fix the error by upgrading the runtime, compiling with –release, or upgrading Gradle, Spring, JaCoCo, Mockito and Lombok.
Fix This version of ChromeDriver only supports Chrome version with Selenium Manager, a clean PATH, a pinned Chrome for Testing build or WebDriverManager.
Fix Java OutOfMemoryError by its message, from heap space and Metaspace to native threads, with JDK 25 output, container settings and heap dump analysis.
Fix class file has wrong version 61.0, should be 52.0 by building with JDK 17+ in Maven, Gradle, IntelliJ and Eclipse. Includes a class version table.
Fix the JMH error Unable to find the resource /META-INF/BenchmarkList on JDK 23+ with Maven processor paths, proc full, Gradle and shaded JARs.
Java tutorial for beginners on Java 25. Install the JDK, run a first program and follow a 12-step learning path plus an index of every Java topic.
throw vs throws in Java compared with a table and examples, plus exception propagation, rethrowing and the throws rules for overriding methods.
Java try catch finally with runnable Java 25 examples, the order the blocks run, multiple catch blocks, return in finally and when finally is skipped.
Fix InvalidKeyException Parameters missing by passing the IV to Cipher.init(), with AES-GCM IV storage and InvalidAlgorithmParameterException causes.
SSLHandshakeException means the Java client and the server could not agree on a TLS connection. Fix TLS version mismatches with jdk.tls.client.protocols, untrusted certificates with keytool, and find the rest with javax.net.debug.
ClassNotFoundException for org.apache.commons.fileupload.FileItemFactory means the JAR is missing. Fix it for Spring 6, Jakarta servlets and legacy apps.
Fix javax.servlet.http.HttpServlet was not found on the Java Build Path in Eclipse with the servlet API or Tomcat runtime, plus the Tomcat 11 jakarta fix.
Fix IllegalStateException No match found in Java regex by checking matches() or find() before group(), with named group pitfalls and Java 25 examples.
Tomcat throws taglib definition not consistent with specification version for a misplaced taglib in web.xml. See both cases and the Jakarta EE fix.
Checked vs unchecked exceptions in Java explained with the Throwable hierarchy, compiler rules, Java 25 examples and when to choose each kind.
Fix java.lang.IncompatibleClassChangeError Implementing class by finding duplicate jars, solving cglib and ASM conflicts and moving to Byte Buddy.
A Java NullPointerException means code used a null reference as an object. Read the helpful NPE message, learn the common causes, and avoid NPEs with requireNonNull, Optional, default values, case null and JSpecify annotations.
Java suppressed exceptions explained with try-with-resources, getSuppressed() and addSuppressed() examples, stack trace output and suppressed vs cause.
How to write custom exceptions in Java with cause constructors, a sealed hierarchy, context fields, JUnit tests and the common mistakes to avoid.