Java Synchronous and Asynchronous Exceptions

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

1. Asynchronous and synchronous exceptions

Normally Java differentiate the exceptions in 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 in two categories.

  1. Synchronous exceptions
  2. Asynchronous exceptions

2. Synchronous exception

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

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

For example, we run a Java program ‘N’ times with same input. If NullPointerException occur at line number ‘M’ then they will occur at a same line number every time. This is example of synchronous exception 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 as well as Java interviews.

Happy Learning !!

Read More: Oracle Docs

Leave a Reply

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