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
Throwablethat 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:
OutOfMemoryErrorStackOverflowErrorAssertionErrorNoClassDefFoundError
Here are the remaining errors in the standard API:
AnnotationFormatErrorAWTErrorCoderMalfunctionErrorIOErrorFactoryConfigurationErrorFactoryConfigurationErrorLinkageErrorServiceConfigurationErrorThreadDeathTransformerFactoryConfigurationErrorVirtualMachineErrorInternalErrorUnknownErrorClassCircularityErrorClassFormatErrorExceptionInInitializerErrorIncompatibleClassChangeErrorUnsatisfiedLinkErrorVerifyError
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.
加载中,请稍侯......
精彩评论