Error, exception, runtimeexception

Source: Internet
Author: User

Errors are thrown by virtual machines, such as Oom, internal errors in the system, and resource depletion. In this case, programmers do not have to give up or give up ..

Exception, which is the parent class of all exceptions. Here I will divide it:Runtimeexception and non-runtimeexception. (The former is called an unchecked exception, and the latter is called a checked exception)

The runtimeexception system is generally a programmer's fault. For example, incorrect type conversion, out-of-bounds array access, and attempts to access null pointers.

    • If this exception is not caught, eclipse will not report an error. The exception will be thrown up until the thread is stopped. For debugging, very good.
    • Of course, you can also catch and perform some processing. Ignore the mistakes that have been made by yourself. Will this be a little ostrich?
    • ProgramYou canCodeAnd check the array subscript and array boundary to avoid array out-of-bounds access.

Non-runtimeexception System

    • Such exceptions are often caused by external factors, rather than programmer errors. For example, an attempt to read data from the end of a file
    • To be thrown, it must be captured at a layer.

Runtimeexception and error can be generated in any code. They do not need to be thrown by the programmer. Once an error occurs, the corresponding exception is automatically thrown. When an error occurs, programmers are generally powerless. In the case of runtimeexception, the program must have a logic error and must be modified.

 

The checked exception is thrown by the programmer. There are two situations: the programmer calls the library function that throws the exception (the Library Function exception is thrown by the library programmer ); the client programmer throws an exception using the throw statement. Only the checked exceptions are the concern of the programmer. The program should and should only throw or handle the checked exceptions.

 

The subclass method that overrides a method of the parent class cannot throw more exceptions than the parent class method. Therefore, when designing the parent class method, an exception is declared, however, the Code of the actual implementation method does not throw an exception, so that the subclass method can throw an exception when overwriting the parent class method.

 

Http://hi.baidu.com/ailongni/blog/item/ce75c734ec11cb1990ef3988.html

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.