-----------Android Training, Java training, Java Learning Technology blog, look forward to communicating with you. ------------
Format of exception Handling statements
1.
try{
}catch () {
}
2.
try{
}catch () {
}finally{
}
3.
try{
}finally{
}
The embodiment of the exception in the child parent class coverage
1. When a subclass overrides a parent class, if the method of the parent class throws an exception, then the overridden method of the subclass can only throw the exception of the class or subclass of the exception.
2. If the parent class method throws more than one exception, the subclass can only throw a subset of the parent class exception when it overrides the method.
3. If the parent class or the method of the last interface does not throw an exception, then the subclass cannot throw an exception when it overrides the method. If the parent class method has an exception, you must do a try processing and never throw it.
Exception Summary:
An exception is a description of the problem, which encapsulates the object
The characteristics of the anomaly system: all the classes in the anomaly system and the objects that are created have the ability to be parabolic, that is, they can be manipulated by throw and throws keywords, only the anomaly system has this characteristic.
Throws is defined on functions to throw exception classes, which can be thrown in multiple, separated by commas.
Throw is used within a function to throw an exception object.
When the function content has throw throw exception object, does not carry on the try processing, must declare on the function, otherwise the compilation fails.
Note that except for runtimeexception, that is, if you throw a Runtimeexceptionn exception within a function, you can use the function without declaring
If the function declares an exception, the caller needs to handle it, and the processing method can be throws to try
There are two kinds of exceptions: compile-time detected exceptions
Run-time exceptions (not detected at compile time)
The benefits of an exception
1. Encapsulate the problem
2. Separate the normal process code from the problem handling code for easy reading.
Exception Handling principle:
1. There are two ways of handling, try or throws
2. Call to throw the function of the exception, throw a few, on the processing of several. A try can correspond to multiple catch
3. Catch of multiple catch parent classes is placed at the bottom.
4. There is a need to define a targeted approach within a catch. Don't printstacktrace. Output statements also do not write.
When an exception is caught, this feature cannot be processed and can continue to be thrown in a catch.
If the exception cannot be handled, but does not belong to the exception of the feature, you can convert the exception after throwing the exception associated with the feature.
Or the exception can be handled, when the exception is required to be produced and the painting can be related to the problem provided out, when the caller knows, and processing, you can also catch the exception button to transform the new exception
Unusual considerations:
1. When the child parent class overrides, the exception thrown by the subclass must be a subclass or subset of the exception of the parent class.
2. If the parent class or interface does not throw an exception, the subclass overrides an exception, and only try cannot be thrown.
Package
1. Classification management of class documents
2. Provide multiple namespaces to class
3. Written in the first line of the program file
4. The name of the class is the name of the package. Class Name
5. Name is also a form of encapsulation.
The access between the package and the package, the classes in the package being accessed, and the members in the class are decorated with public.
Subclasses in different packages can access members modified by the protected permission in the parent class
There are only two types of permissions that can be used between packages and packages, public protected
In order to simplify the writing of the class name, make the winner a keyword, import