DEV Community

Cover image for What is an Exception?
Tristan Elliott
Tristan Elliott

Posted on • Updated on

What is an Exception?

Introduction

  • This is the first post in my exception series. Hopefully we can both learn more about exceptions in Java. This post only contains definitions, no code.

What is an exception

  • The term exception is short for exceptional event and it means an event which occurred during the execution of a program, that disrupts the normal flow of a program's instructions.

  • When an error occurs within a method, the method creates an object and hands it off to the Java runtime environment.

What is the Java runtime environment(JRE)?

  • to put it simply, it is just a software layer that runs on top of a computer's operating system and provides the appropriate resources that the specific Java application would need. In general terms, a "Runtime Environment" is just a piece of software that runs other software.

  • the Java runtime environment consists of two main parts

  • 1) class loader : which is responsible for correctly loading classes and connecting then with the core Java class libraries.

  • 2) Java Virtual Machine : is responsible for ensuring Java applications have the appropriate resources needed to perform properly.

  • The JRE (Java Runtime Environment) acts mainly as a container and is responsible for orchestrating all of their activities.

  • After a method throws an exception, the JRE attempts to find "something" to handle it. To find this "something" the JRE searches the call stack for a method that contains "something" that can handle the exception. This "something" is called an exception handler.

  • A call stack is a data structure that represents all the currently active methods that have been called but are not returned.

  • The search on the call stack begins with the method in which the error occurred and proceeds through the call stack in reverse order. When an appropriate handler is found the JRE passes the exception to the handler.

  • If the JRE searches all the methods on the call stack without finding an appropriate exception handler the entire system terminates

Conclusion

  • Thank you for taking the time out of you day to read this blog post of mine. If you have any questions or concerns please comment below or reach out to me on Twitter.
  • Also make sure to checkout my YouTube channel for more programming tutorials

Top comments (0)