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