One: Anomaly classification
(1) The Throwable class is the ancestor of all exceptions, and it has two direct subclasses error/exception:
Error throws an Error object only if there is a dynamic connection failure in the Java Virtual machine or when other positioning fails. The general program does not need to catch or throw an Error object.
(2) Unchecked Exception:
A. refers to a flaw in the program or a logic error and cannot be recovered at run time.
B. including error and runtimeexception and their subclasses such as: OutOfMemoryError, Undeclaredthrowableexception, IllegalArgumentException, Illegalmonitorstateexception, NullPointerException, IllegalStateException, indexoutofboundsexception and so on.
C. The syntax does not require a declaration to throw an exception.
(3) Checked Exception:
A. Invalid external situations (such as user input, database problems, network anomalies, file loss, etc.) that are not directly controlled by the program.
B. In addition to the error and runtimeexception and their subclasses, such as: ClassNotFoundException, Namingexception, Servletexception, SQLException, IOException and so on.
C. Requires a try-catch-handling or throws declaration to throw an exception.
Two: the principle of exception handling
1, at the framework level package checked exception, convert it into unchecked exception, avoid the development process of writing cumbersome Try...catch code.
2, the development of the business level, according to the program code responsibility to define different runtimeexception (it is unchecked exception, generally defined as RuntimeException subclass)
3, through the first two views, the system of the custom exception will only exist unchecked exception, the system is only the upper layer of the client Exchange data, set up a unified exception handling mechanism, and some exceptions to the user can understand the message conveyed to the user.
4, other such as business layer, data persistence layer, and so on the bottom is only responsible for the exception can be thrown, but be careful not to lose the exception stack (this is a beginner easy to make a mistake).
Three: Examples of Jersey exception handling mechanism
(1) Create a Exceptionmappersupport unified exception handler under the API package
(2) Custom Exceptions
Exception parent class; persistent layer exception; Business Layer exception
(3) DAO layer exception thrown persistenceexception
(4) Business logic Layer action throws Webactionexceptiontype
(5): Custom Exception friendly hints
(6): API call, exception resolution
(7): Abnormal hint effect