Error vs Exception
Tags: 100daysofcode, codenewbie, beginners
Published: 2021-06-22 16:19:24

---
title: Error vs Exception
published: true
date: 2021-06-22 16:16:31 UTC
tags: 100daysofcode, codenewbie, beginner
canonical_url: https://bharadwaj.hashnode.dev/error-vs-exception
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/28llh14b6ja1v5dd6nqj.png
---

One of the most difficult parts of programming languages is to know the difference between Error and Exception. I used to get confused a lot about this. So, to help my mates to overcome this problem, I thought of writing a blog on it. After a long time experimenting, I have decided to write this blog in a table fashion(sounds odd, but easy to understand). Here you go.

**What is an Exception?**

An exception is an event that occurs during the execution of a program that disrupts the normal flow of instructions during the execution of a program.

**What is an Error?**

Errors are the mistakes or faults in the program that causes the program to behave unexpectedly.

**Types of Exception**

Exception: Most languages throw an exception at run-time except java. Java provides two types of exceptions. Let's see them.

Checked Exception: Checked exceptions are known to the compiler and must handle at compile time.

Unchecked Exception: These errors are not checked at runtime.

**Types of Error**

Compile Time Error/ Syntax Error: Common syntactical mistakes in the code.

Run Time Error: Run time errors that are caused by the environment in which the program is running.

Logical Error: Mistakes in the logical flow of the program.

Here comes the **Point of Confusion** :

- Only confusion is between run-time errors and exceptions.
- An exception is something that interrupts the normal flow of the program.
- Something exceptional has happened within the program which should be handled to run the program uninterruptedly.
- An exception that can be handled even in the compile-time in a language like java while that is not true in the case of run-time error.
- Most of the run-time errors caused by the environment in which the application is running.
- An error must be resolved. You simply cannot ignore them.

**Exception**

- They are caused by the program itself.
- Null reference exception is when the program tries to access the property of the null object.
- You can recover from the exceptions by handling them through try-catch classes.
- It is recommended to handle exceptions in the program.

**Error(Run-Time)**

- Errors are mostly caused by the environment in which the application is running.
- OutOfMemoryError occurs when JVM runs out of memory or StackOverFlow error occurs when stack overflows.
- You cannot recover the program from the error. So, you must resolve the error.

**Examples of Exception**

- NullPointerException
- ArrayIndexOutOfBoundException
- IOException

**Example of Errors**

- OutOfMemoryError

**Summary**

- So, Exception is not a run-time error.
- There is a clear difference between errors and exceptions in a language like java.
- Different languages interpret error differently.

That's a wrap. Share your thoughts in the comment section. Connect with me on [Twitter](https://twitter.com/Bharadwaj6262) for more awesome content.