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

Was this post helpful?

Join 7000+ Fellow Programmers

Subscribe to get new post notifications, industry updates, best practices, and much more. Directly into your inbox, for free.

1 thought on “Java synchronous and asynchronous exceptions”

  1. Thanks a lot Lokesh. This discussion was really so much practical and helpful to go in depth of Java programming. Thanks a lot !!

    Reply

Leave a Comment

HowToDoInJava

A blog about Java and its related technologies, the best practices, algorithms, interview questions, scripting languages, and Python.