Sponsored Links

Ad by Google
In java exception is very powerful feature and we have already seen about the Exception in our Exception Tutorial. And in this tutorial, I will try to explain about one of the sub class of Exception called java.lang.Error, and after completion of this tutorial, you will be able to answer what is Error in java? and few examples of Error sub-classes.

What is java.lang.Error in java?
The java.lang.Error is another sub class of java.lang.Throwable class, which indicates serious problems and application cannot recover from this Error unlike Checked Exceptions. And also a better design of Exception handling is to not handling the Error because handling of error will does not make any sense, so no need to catch or throw  Error or any sub class of Error.

The java.lang.Error including it's sub classes also know as UN-checked exception like Runtime Exceptions
The common reason of occurring this error in your application is possible that due no space in stack and trying to allocating more memory in stack, application runs out of memory, suddenly virtual machine crashed, no resource available to perform any task by jvm etc.

Sometimes due to coder's mistake this error also seen, specially if you are not very cleared about how to use recursion possible that you will see this error, below is the sample code which will gives you a StackOverflowError in your code, try with below code.

public static void main(String[] args) {
  List list1 = new ArrayList<>();
  List list2 = new ArrayList<>();
Exception in thread "main" java.lang.StackOverflowError
at java.util.ArrayList$Itr.next(ArrayList.java:791)
at java.util.AbstractList.equals(AbstractList.java:521)
at java.util.AbstractList.equals(AbstractList.java:523)
at java.util.AbstractList.equals(AbstractList.java:523)
at java.util.AbstractList.equals(AbstractList.java:523)

Few very popular Errors-
  1. StackOverflowError
  2. OutOfMemoryError
  3. NoClassDefFoundError
  4. InternalError
  5. IOError
  6. AssertionError

Sponsored Links


Post a Comment