Concept of 1.Java anomaly
- Examples of exceptions
- 1. Division is an example of an exception that needs to be caught, and the divisor may be 0
- exception handling the basic process is as follows
- Once an exception occurs, the program does not follow the original process to continue to run
- A. Program throws an exception
-
- try{
- throw new Exception ();
- }
- B. Catching exceptions
- c.finally code block
- It is important to note that an exception cannot be thrown in a finally block.
-
- finally{
- //must be executed /em>
- //unless There is system.exit (0) in the catch, the Java Virtual machine will be launched
- }
li>
- Summarize:
- 1. When an exception is thrown in the program, the program jumps out of the code that caused the exception in the program, the Java Virtual machine detects the catch block that handles the exception that matches the try keyword, and if found, the code in the catch block, then proceeds to execute the program, The code for the exception that occurred in the try block is not re-executed. If no catch block is found to handle the exception, then the finally block code is Executed.
- 2. The run function of a thread cannot throw an exception (it can be captured and processed inside the function, but cannot be committed), and the exception of the run function is submitted to Uncaughtexceptionhandler for processing, and later changes will be described in detail
- 3. The other functions of the run function can be submitted to the superiors by the exception thrown in the Function.
- Exception classification
- 1.unckeckedexception--error (inaccurate, But the Error is actually checked and thrown at Runtime) and runtimeexception-------no replenishment is required in the program
- 2.checkedException-----ioexception, classnotfoundexception, clonenotsupportedexception
- The check here is not checked against the compiler
- Common runtimeexception-nullpointerexception, Array out-of-bounds, string out-of-bounds, arithmetic error (a/b), parameter type error (integer.parseint ("abc"))
- Cathch exception
- Note: a try block can handle multiple types of exceptions (up to one catch module will be executed, not the same as Switch)
- A logical try after processing multiple exceptions will error-the following code will error [catch subclass exception before catch parent exception]
- Because the latter catch cannot be executed to
-
- try{
- Code
- }catch (Exception E) {
- }catch (runtimeexception E) {//error must not be executed to
- }
- Custom exceptions ----that is, inherit from the exception
- The most important thing is actually the name of the Exception.
- Class MyException extends exception{}
- The default constructor
- 1.super () invokes the constructor of the base class to initialize
- 2.super (message)
Reference: Http://www.codeceo.com/article/java-exception-learn.html#0-tsina-1-56987-397232819ff9a47a7b7e80a40613cfe1
2.Java Abnormal Learning