Java Exceptions basic knowledge and exceptions in the spring framework of the overall solution

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.