ABP Source Code Analysis 47: Exception Handling in ABP

Source: Internet
Author: User

The idea of exception handling in ABP is very clear. There are altogether five types of exception classes.

Abpinitializationexception is used to encapsulate exceptions that occur during ABP initialization, as long as the abpinitializationexception exception is thrown and no additional processing is required. Such anomalies are often required for maintenance personnel to intervene in the analysis.

The other four exceptions are centrally processed in Abpcontroller, and the processing is divided into two steps: one, the exception event is triggered by Eventbus, and the corresponding exception handler handles the exception. For Abpvalidationexception,userfriendlyexception and Abpauthorizationexception exceptions, the ABP converts the exception information to ErrorInfo, and returned to the client as either view or JSON.

abpexception: base class for all custom exception classes in the ABP.

userfriendlyexception: Inherits from the Abpexception class, implements the Ihaslogseverity interface. The user can encapsulate an exception that needs to be returned to the client through an instance of Userfriendlyexception.

The actual use of userfriendlyexception samples such as the next

Iexceptiontoerrorinfoconverter: Defines a method for converting exception to errorinfo. Also defines a pointer to a self-contained object next, the author's intention is to attempt to construct a chain of exceptiontoerrorinfoconverter instances in a chain of responsibility, where each instance is used to convert a type of exception to ErrorInfo. For now, however, the ABP does not implement this functionality in this way, but instead plugs all the functionality into a Defaulterrorinfoconverter class.

Defaulterrorinfoconverter: Implements the Abpvalidationexception, Userfriendlyexception and Abpauthorizationexception instances convert exception to ErrorInfo

Ierrorinfobuilder : Defines a method for building a iexceptiontoerrorinfoconverter responsibility chain and a method for converting exception to a errorinfo instance.

Errorinfobuilder: Implements the method defined in interface Ierrorinfobuilder. By constructing the Defaulterrorinfoconverter instance and calling the instance to complete the exception to errorinfo conversion.

Abpcontroller: Override the Onexception method to centralize abpvalidationexception, Where userfriendlyexception and abpauthorizationexception are abnormal. Note where the abpinitializationexception exception is not handled in the ABP, the system automatically terminates if an abpinitializationexception exception occurs.

mvcajaxresponse<tresult>,mvcajaxresponse: Used to encapsulate response information for AJAX requests. Inherits from Ajaxresponse<tresult>, adds a TargetUrl property, and does not override the method in the base class.

Abpjsonresult: Inherit from the Jsonresult of Newtonsoft. The JSON object used to serialize the CLR object to CamelCase.

Custom Exception Event handling functions

Back to ABP source Analysis series Articles Directory

ABP Source Code Analysis 47: Exception Handling in ABP

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.