The top-level parent class for the exception is Throwable, with two subclasses exception and error below.
Error errors are typically virtual machine-related problems, such as system crashes, virtual machine errors, and so on, that the application cannot process, directly leading to the end of the application run.
Exception is the exception we need to handle.
Exception is also divided into checked anomalies and runtime anomalies.
All RuntimeException classes and their subclasses are runtime exceptions. The others are checked exceptions.
The checked exception must show processing and compile errors will occur if no processing occurs.
Runtime and checked are handled in two ways:
1. Throw
2. Catch
Both can be used at the same time, after catch throw new exception
Custom exception Classes
Public class Auctionexception extends exception{ public auctionexception () {} public auctionexception (String msg) { super (msg); } }
Handling exceptions in spring, using AOP to centralize processing
Let's take a look at a few blog posts, which are recommended for reading.
http://blog.csdn.net/he90227/article/details/46309297
Http://www.cnblogs.com/chenpi/p/6117090.html
http://blog.csdn.net/ufo2910628/article/details/40399539
Http://www.cnblogs.com/xd502djj/archive/2012/09/24/2700490.html
In summary, there are three main methods of centralized treatment
(1) using the simple exception processor Simplemappingexceptionresolver provided by spring MVC;
(2) Implement spring's exception handling interface (Handlerexceptionresolver) to customize its own exception handler;
(3) using @exceptionhandler annotations to implement exception handling;
It is recommended to use the last one.
Detailed introduction is made in http://www.cnblogs.com/chenpi/p/6117090.html.
In summary, the principle is to wrap the underlying native exception with a custom business exception, and then do the centralized processing.
Java Exceptions basic knowledge and exceptions in the spring framework of the overall solution