Types of Exceptions
Start course

In this course, we will learn the concepts of microservice and spring framework and focus on Exception Handling.

Learning Objectives

  • Exception Handling in Java 

Intended Audience

  • Beginner Java developers
  • Java developers interested in learning how to Build and Deploy RESTful Web Services
  • Java Developers who want to develop web applications using the Spring framework
  • Java Developers who want to develop web applications with microservices
  • Java Developers who wish to develop Spring Boot Microservices with Spring Cloud


  • Basic Java knowledge

Hello there. In this video, we will talk about the types of exceptions. There are three types of exceptions in Java. The first one is the checked exception. Checked exceptions are mandatory to handle. Checked exceptions are generally caused by faults outside of the code itself, networking errors, etc. These exceptions are checked at a compile time. So, these are also called compile time exceptions. For example, FileNotFoundException is a checked exception and it occurs when a file with a specified path name does not exist, or if the file does exist, but for some reason is inaccessible. Unchecked exceptions, on the other hand, are checked at runtime rather than compile time. As a result, they are also referred to as runtime exceptions. When an unchecked exception is thrown, it is usually caused by misuse of code, passing a null or otherwise incorrect argument. For example, arithmetic exception is an unchecked exception and it occurs when you make an arithmetic error, such as dividing a number by zero.

The last one is the user-defined exception. In some cases, depending on the application requirements, we must define our own exception class. For example, let's suppose we have an account in a bank and we have $100 in this account. Assume we attempt to withdraw $150 from our account, naturally we can handle this scenario by using Java's arithmetic exception. However, the user will not find this useful. In this situation it's nice to display some error messages related to insufficient funds, so we can create our own exceptions in Java. We just need to extend the exception class to create our exception. User-defined exceptions are also called custom exceptions. We'll do an exercise on these exceptions later, I promise, but let's take a short break here and I'll see you in the next video.


About the Author
Learning Paths

OAK Academy is made up of tech experts who have been in the sector for years and years and are deeply rooted in the tech world. They specialize in critical areas like cybersecurity, coding, IT, game development, app monetization, and mobile development.