开发者

When does ERROR occurs in Java?

I'm a student and right now going 开发者_StackOverflow社区through exceptions and errors in Java.

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


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


Errors are generally used to signal serious technical problems that an application can't do anything to correct. Look at the Javadoc of the error classes and you'll get the idea.


If you run out of memory -- kaboom! OutOfMemoryError! (There really is not much you can expect to do at this point but let the process die and try to restart it - e.g. the very act of trying to respond to this requires memory so it's a catch-22 :-/)


Errors are something you have little or no control over, typically signifies serious problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜