I. Overview of exceptions
Exception: Exception, is an abnormal condition that occurs during a run.
Raw Exception Handling:
if (condition) {Treatment Method 1
Treatment Method 2
Treatment Method 3
}
if (condition) {Treatment Method 4
Treatment Method 5
Treatment Method 6
}
Code reading poor, bloated, and the normal process code is very close, so, in Java a series of improvements, a series of common problems, using object-oriented thinking, the description, encapsulation.
Class handling method { processing Method 1 () { Example 1 } handling Method 2 () { Example 2} }
if (Error)
{
throw new treatment 1 (); This method may contain the name of the problem, the information, the time, the location, and so on.
}
In Java, an abnormal condition is described and encapsulated in the form of a class. When there is a problem with the program, call the appropriate processing method.
A class that describes an unhealthy condition is called an exception class. Separates the process code from the exception code.
The exception is that Java encapsulates the problem as an object through object-oriented thinking. The exception class is used to describe it. Different problems, describe them in different classes. That means, how many problems there are, and how many classes there are.
second, abnormal system
Many problems, meaning that the description of the class is also a lot, the generality of the extraction, the formation of an anomaly system. The final exception is divided into two main categories :
Throwable (parent Class): The problem occurs, it should be thrown, let the caller handle it. The characteristic of this system is that both Throwable and its subclasses have parabolic properties.
Two keywords to achieve the parabolic: throws, throw
|--1. Generally non-processing. Error (Errors)
Feature: A problem with the severity thrown by the JVM (Java Virtual machine). This problem occurs, generally not targeted treatment, directly modify the program.
|--2. can be processed. Exception (Exception)
Features: The suffix of the subclass is the suffix of its parent class name, and the reading is very strong.
third, exception-principle & Throw Throw of exception object
Throw new Exception Method ();
Try-catch-finnal exception Handling in Java (Learning notes)