Java Exception Log Assertion debugging

Source: Internet
Author: User

Exception hierarchy for exceptions Java

ErrorThe class hierarchy describesJavainternal errors and resource exhaustion errors for the runtime system.The referencing program should not throw objects of this type.if such an internal error occurs,In addition to informing users,and try to make the program safely terminated .,There's nothing more to do..

in the designJavaprogram when,need to pay attentionExceptionHierarchical Structure.This hierarchy is decomposed into two branches:a branch is derived from theruntimeexception;Another branch contains other exceptions.the rules for dividing two branches are:exceptions caused by program errors belong to runtimeexception;and the procedure itself is no problem.,but because likeI/Oan exception that is caused by an error such as a problem belongs to another exception.
    derived from runtimeexception exception contains the following conditions :
1. Wrong type conversions

2. data Access is out of bounds
3. Accessing the null pointer

not derived fromruntimeexceptionthe exceptions include:
1.attempting to read data behind the end of the file
2.attempting to open a file that does not exist
3.trying to find the given stringClassObject,and this string represents a class that does not exist
.
    "if it appears runtimeexception Abnormal , then it must be your problem " is a fairly reasonable rule .It should be avoided by detecting whether array subscripts are out of boundsarrayindexoutofboundsexceptionException;This should be done by detecting whether the variables are empty before using them.NullPointerExceptionthe occurrence of an exception.
Java language will be bornErrorclass orruntimeexceptionall exceptions for class are called unchecked exceptions,All other exceptions are referred to as checked exceptions.

runtimeexception The name is easily misunderstood and is not meant to be a runtime exception.

Calling a method that throws a checked exception, the compiler must handle the exception, either caught or thrown.

Calling a method that does not check for exceptions, the compiler does not require that the exception be handled. As follows:

Red Line is compiled error, need to catch an exception to be able.

Why don't we need to catch an unchecked exception?

Because in most cases, unchecked exceptions are generally procedural errors that are beyond our scope of processing. You should avoid this exception during program writing, rather than throwing it to the top. For example, do we need to deal with arrayindexoutofboundsexception exceptions, which are not needed, which is a problem that needs to be avoided during the coding phase.

Java Exception Log Assertion debugging

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.