Java Synchronous and Asynchronous Exceptions

In this Java tutorial, learn about asynchronous and synchronous exceptions in Java. Also, learn how they are different with checked and unchecked exceptions.

1. Asynchronous and synchronous exceptions

Normally Java differentiates the exceptions into two categories on basis of “timing” when they are discovered. These categories are checked and unchecked exceptions.

Similarly, on the basis of place of occurrence, Java exceptions can be divided further into two categories:

  • Synchronous exceptions
  • Asynchronous exceptions

2. Synchronous Exception

Synchronous exceptions happen at a specific program statement, no matter, how many times we run a program in the similar execution environment.

Examples of synchronous exceptions are what we care for in our daily life as developers i.e. NullPointerException or ArrayIndexOutOfBoundsException etc.

For example, we run a Java program ‘N’ times with the same input. If NullPointerException occurs at line number ‘M’ then they will occur at the same line number every time. This is an example of synchronous exceptions in Java.

3. Asynchronous exception

Asynchronous exceptions can raise practically anywhere. It follows that asynchronous exception handling can’t be required by the compiler. They are also difficult to program with.

Examples of naturally asynchronous events include pressing Ctrl-C to interrupt a program or receiving a signal such as “stop” or “suspend” from another thread of execution. For example, if you press ‘CTRL + C’ N times during application execution, no one can guarantee the line number on which the application will end.

I hope that this discussion about Java synchronous and asynchronous exceptions will help you in programming activities and Java interviews.

Happy Learning !!

Comments

Subscribe
Notify of
guest
1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.

Our Blogs

REST API Tutorial

Dark Mode

Dark Mode