Types of Exceptions

Start course
Overview
Difficulty
Beginner
Duration
50m
Students
24
Description

In this course, we'll learn about Exception Handling in Java.

Learning Objectives

  • What is an Exception?
  • Difference between Error and Exception
  • Types of Exceptions
  • Try-Catch Block
  • Finally Block
  • Throw and Throws Keywords
  • Exception Methods

Intended Audience

  • Anyone looking to get Oracle Java Certification
  • Those who want to learn the Java Programming language from scratch
  • Java developers who want to increase their knowledge
  • Beginners with no previous coding experience in Java programming
  • Those who want to learn tips and tricks in Oracle Certified Associate – Java SE 8 Programmer certification exams

Prerequisites

  • No prior knowledge is required about the Java programming language
  • Basic computer knowledge
Transcript

Hi there. In this video, we'll 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, such as missing resources, networking errors, etc. These exceptions are checked at 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 specific path name does not exist or if the file does exist but for some reason is inaccessible. The second one is unchecked exceptions and they are not checked at compile time but they are checked at runtime. So, these are also called runtime exceptions. When an unchecked exception is thrown, it's usually caused by a 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, we need to define our own exception class for special purposes based on application requirements. For example, let's suppose we have an account in a bank and we have $100 in this account. Think that we attempt to withdraw $150 from our account. Of course, we can handle this scenario by using Arithmetic Exception in Java but this is not meaningful for the user. 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 about these exceptions later. Let's take a short break here. I'll see you in the next video.

 

About the Author
Students
512
Courses
47
Learning Paths
3

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.

Covered Topics