Java Exceptions

Java ArrayStoreException and How to resolve it?

Learn why we get the ArrayStoreException while working with arrays in Java and how to identify the root cause and fix this error. 1. Root Cause of ArrayStoreException Java arrays are covariant and support the subtyping rules of Java, an array of type T[] may contain elements of type T …

[Solved] Error: Could not find or load main class

We may get this error (Could not find or load main class) while running the Java class (e.g. Hello world application) from the system console. We get this error because we are incorrectly trying to run the main() inside the class using java command. 1. Reason for error – could …

Java 14 – Helpful NullPointerException (NPE)

Java 14 (JEP 358) improves the usability of NullPointerException generated by the JVM by describing precisely which variable was null. Lets understand this in detail. 1. Better NullPointerException First, we need to pass -XX:+ShowCodeDetailsInExceptionMessages JVM flag to enable this feature while running the application. Make sure, you are passing it. …

Java throw and throws Keywords

In Java exception handling, throw keyword is used to explicitly throw an exception from a method or constructor. And throws keyword is used to declare the list of exceptions that may be thrown by that method or constructor. 1. Throw Let us learn basic things about throw keyword before going …

Java try catch finally

Java try catch finally blocks helps in writing the application code which may throw exceptions in runtime and gives us chance to recover from the exception.

Jersey exception handling – Jersey ExceptionMapper Example

In Jersey ExceptionMapper example, we will learn to handle custom exceptions using ExceptionMapper interface while developing Jersey RESTful web services. For demo purpose, I am modifying the sourcecode written for jersey download file example. Table Of Contents 1. Jersey custom exception with ExceptionMapper 2. How to throw exception from REST …

Restarting threads using UncaughtExceptionHandler

1. UncaughtExceptionHandler Java applications have two kind of exceptions – checked exceptions and unchecked exceptions. Checked exceptions must be specified in the throws clause of a method or caught inside them. Unchecked exceptions don’t have to be specified or caught. When a checked exception is thrown inside the run() method …

Guide to Java 8 Optional

All of us must have encountered NullPointerException in our applications. It happens when you try to use an object that has not been initialized, initialized with null or does not point to any instance. In simple words, NULL simply means ‘absence of a value’. In this Java tutorial, we will …

Java Checked vs Unchecked Exceptions

Learn the difference between checked vs unchecked exceptions in Java, with simple explanations and examples. Learn Java exception handling best practices.

[Solved] java.lang.IncompatibleClassChangeError: Implementing class

Reason When you are working with java libraries that internally depend on cglib, then it’s very normal to encounter the below error: This error is due to an incompatible version of cglib with additional jar files in your project, such as asm. Solution The solution is very easy. Just place …

Java NullPointerException

Java NullPointerException (NPE) is an unchecked exception and extends RuntimeException. NullPointerException doesn’t force us to use a try-catch block to handle it. NullPointerException has been very much a nightmare for most Java developers. It usually pop up when we least expect them. I have also spent a lot of time …

Java Suppressed Exceptions with Examples

Suppressed exceptions, as name suggest, are exceptions thrown in the code but were ignored somehow. If you remember try-catch-finally block execution sequence and how they return any value or exceptions, you will recall that exceptions thrown in finally block are suppressed if an exception is thrown in try block also. …

Java Synchronous and Asynchronous Exceptions

In this Java tutorial, learn about asynchronous and synchronous exceptions in Java. Also, learn how they are different with checked and unchecked exceptions. 1. Asynchronous and synchronous exceptions Normally Java differentiates the exceptions into two categories on basis of “timing” when they are discovered. These categories are checked and unchecked …

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.