Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does ERROR occurs in Java?

Tags:

java

exception

I'm a student and right now going through exceptions and errors in Java.

I have a confusion about when error occurs. Please share with me some examples.

like image 953
ioraraj Avatar asked Nov 07 '10 08:11

ioraraj


People also ask

Why does error occur in Java?

In Java, an error is a subclass of Throwable that tells that something serious problem is existing and a reasonable Java application should not try to catch that error. Generally, it has been noticed that most of the occurring errors are abnormal conditions and cannot be resolved by normal conditions.

What is meant by error in Java?

In java, both Errors and Exceptions are the subclasses of java. lang. Throwable class. Error refers to an illegal operation performed by the user which results in the abnormal working of the program. Programming errors often remain undetected until the program is compiled or executed.


1 Answers

Errors are Throwables that you're not supposed to / expected to catch, such as OutOfMemoryError or StackOverflowError.

From the Java documentation on Error:

An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions. The ThreadDeath error, though a "normal" condition, is also a subclass of Error because most applications should not try to catch it.

Here are some of the more common errors:

  • OutOfMemoryError
  • StackOverflowError
  • AssertionError
  • NoClassDefFoundError

Here are the remaining errors in the standard API:

  • AnnotationFormatError
  • AWTError
  • CoderMalfunctionError
  • IOError
  • FactoryConfigurationError
  • FactoryConfigurationError
  • LinkageError
  • ServiceConfigurationError
  • ThreadDeath
  • TransformerFactoryConfigurationError
  • VirtualMachineError
  • InternalError
  • UnknownError
  • ClassCircularityError
  • ClassFormatError
  • ExceptionInInitializerError
  • IncompatibleClassChangeError
  • UnsatisfiedLinkError
  • VerifyError
like image 100
aioobe Avatar answered Sep 21 '22 01:09

aioobe