Java Exception System
|--throwable Implementation class Description Java errors and exceptions are generally referred to hardware processing
|--error (error) is generally not handled by code , generally by hardware protection
|--exception (Exception)
|--runtimeexception (Run-time exception)
|--non-run-time exceptions
The order in which multiple Try-catch statements are associated
1, sequential execution, from top to bottom, there is a catch clause after matching, the following automatic is not executed
2. If there is a parent-child relationship in multiple Cach
Be sure that the subclass exception is on, the parent class exception is in the next
Custom Exception Types
generally provides two construction parameters, one parameter with no argument, and the parameter is usually called by the parent class. parameter constructor, call form super (message)
run-time exception
RuntimeException
| -- classcastexception can be used in polymorphic instanceof to circumvent
| -- ArithmeticException make if judged, spat over the divisor for 0 make return
| -- NullPointerException make if determine if the NULL
| -- arrayindexoutbondsexcetion Working with Arrays length property to avoid array Out of bounds .
At the time of exception handling, we often throw out the captured Huawei runtime exception, especially when writing some function frames. throw new RuntimeException (e);
non-run-time XOR ( exception to be inspected ) These exceptions must be made Try-catch otherwise the compiler has no Law passed Precautions
1. When asubclass overrides a method of a parent class , the parent class method throws an exception, and the overridden method of the subclass can either throw an exception or raise the same exception as the parent class method, or throw a subclass of the parent method exception.
2. The parent class method throws more than one exception, and when the subclass overrides the method, only a subset of the parent exception is thrown
3. The parent class does not throw an exception, and the subclass cannot throw an exception. Try-catch processing is required when a subclass has a non-runtime exception
4. Subclasses cannot throw more exceptions than the parent class.
Everything should be in line with the parent class, and the parent class should be aligned to the classification.
finally blocks are typically used to release resources regardless of whether the program is executing a finally block
1. There is only one casewhere theJVM exits system.exit (0) and does not perform finally content
2.return statement also cannot prevent finally execution
(3) Simply talk about the exception system in Java