What is an exception: the error generated by the Java program Runtime, which encapsulates all the resulting exceptions into an object called Throwable, which is the parent of all exceptions
Throwable contains 2 sub-classes of Error and Exception
Error: The rep is a 1 program error, especially a low-level, non-recoverable, serious error
Performance: 1. Error occurs when the program exits because the physical environment required to run the program is lost
2. We are unable to process error
Exception: Due to specific factors, the program cannot continue, but does not affect the JVM's normal operation
No exception checked (Runntime Exception)
No necessary checks are made by the programmer, the program can be compiled successfully, the runtime error occurs (memory overflow ...)
Checked for exceptions (non-runntime Exception)
Exceptions are unavoidable and must be handled abnormally, otherwise it cannot be compiled (IO operation, net,thread,jdbc ...)
Exception handling mechanism:
1. When the program is written: A statement may have an exception
The 2.Java mechanism throws a throw to an exception object (xxxexception)
3. The statement after the program does not execute, automatically returns to the previous level method, and the previous method accepts the exception object for processing
4. Treatment of the upper-level approach
--the method has the ability to process (process in this method)
--the method does not have the ability to process (continue to throw), if the current method is main, he throws the JVM, which causes the JVM to terminate the program's run
How the exception is handled
Throws and try-catch--[finally] blocks complete
Problems when writing exceptions
1. Try---correspond to several catch or a finally: the main observation of the try-catch-finally appearance of the hierarchy problem
Abnormal use of 2.Throws and THORW
Throws: Indicates that a method may produce an exception when executed, only for the method's declared format: [method name Throws Xxxexception]
Throw: can only be written in the method, which indicates that an exception format is generated actively [throw exception object]
Custom exceptions
Write a class that inherits Exception or Inherits Runntimeexception
Back to Java Memoirs (ix): Use of java09 exceptions