image
Difference Between Error and Exception
Start course
Difficulty
Beginner
Duration
30m
Students
22
Ratings
5/5
Description

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

Prerequisites

  • Basic Java knowledge
Transcript

Hello there, in our previous video, I explained what an exception is. In this video, we will talk about the difference between error and exception. If you're ready, let's go. Error is a critical condition that cannot be handled by the code of the program. Exception is an exceptional situation that can be handled by the code of the program. The important difference between error and exception is that an error is caused due to a lack of system resources, but an exception is caused because of your code or program. Let's look at other differences between error and exception  along with a comparison chart. As you see in the table, in Java, errors are defined in the java.lang.Error package, but exceptions are defined in the java.lang.Exception package. An error is caused due to a lack of system resources, an exception is caused because of the code. It's impossible to recover from errors, but you can recover from exceptions by handling them through try-catch blocks.

Errors are classified as unchecked types, exceptions are classified as checked or unchecked types. StackOverflowError and OutOfMemoryError are two examples of errors. Exception examples include: ClassNotFoundException and NullPointerException. Now, let's take a look at the hierarchy of the Java exception class. As you can see in the diagram, Object is the top-most class in Java. All the classes extend the object class by default in Java. It is the super class. Here, Throwable is the top-most class of exception classes and it is located in the java.lang package. Throwable has two subclasses, error and exception. Exceptions have been categorized in two ways: built-in exceptions and user-defined exceptions. All checked and unchecked exceptions are built-in exceptions of Java. Okay, let's take a short break here. In the next video, we will learn about these exceptions in detail. So, I'll see you in the next video, my friends.

 

About the Author
Students
3995
Courses
64
Learning Paths
5

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.