1. solution:
(1) it supports Exception Handling for the entire Program architecture layer, it is not limited to the limits of service interfaces.
(2) It enables the exception handling policy to be defined and maintained at the management level, so that the decision makers (possibly system administrators and developers) can define how to handle exceptions. They can maintain and modify the rule set that controls exception handling without changing the block application Code .
(3) it provides common exception handling functions, such as recording exception information and hiding sensitive information by replacing the original exception with other exceptions, the exception context information can be added by packaging the original exception to another exception. These functions are encapsulated in the. NET class named exception handlers.
(4) it can combine multiple exception handlers to generate the response required for an exception. For example, it can record the exception information before replacing the original exception with other exceptions.
(5) It enables developers to create their own exception handling programs.
(6) it calls the exception handling program in the same way. This means that the processing program can be used in a variety of scenarios between applications.
2. use Cases:
Exception Handling application blocks are designed to support typical code contained in catch statements of application components. This application block allows developers to encapsulate this logic into reusable exception handlers, rather than repeating this Code (for example, recording exception information) in the same Catch Block of application components ). The exception handler is A. Net class that encapsulates the exception handling logic and implements the block interface of the exception handling application named iexceptionhandler. The exception handling application block contains four exception handlers:
(1) wrapper handler (WRAP handler ). This exception handler can encapsulate one exception into another.
(2) Replace handler ). This exception handler can replace one exception with another.
(3) logging handler ). This exception handler can format exception information, such as messages and stack traces. The log handler then provides the information to the Enterprise Library log and standard application block for publishing.
(4) fault contract exception handler. this exception handler is designed for use at windows Communication Foundation (WCF) service boundaries, and generates a new fault contract from the exception.
The Exception Handling Application Block allows you to associate the exception type with the specified policy. You can use the configuration console to complete this task. The policy specifies the exception handling program that is executed when the Application Block processes a specific exception type. You can concatenate these handlers so that you can execute a series of handlers when handling the associated exception types.
3. Use:
Use the entlib Configuration tool, new "ehab"-> new "exception Policy"-> new "exception type ". You can create the following common exception handling policies:
(1) propagate policy:Throw the original exception; configure the posthandlingaction = policyrethrow;
(2) wrap policy:Use another exception to wrap the original exception. Configure the abnormal posthandlingaction = thrownewexception, add the wrap handler, and configure the wrapexceptiontype to specify the exception type after packaging (which can be a custom type );
(3) Replace policy:Replace the original exception with another exception. Configure posthandlingaction = thrownewexception, add replace handler, and configure replaceexceptiontype to specify the exception type after replacement (which can be a custom type );
(4) handle and resume policy:Posthandlingaction = none;
(5) log only policy(Use lab): Configure posthandlingaction = none for an exception, add a logging handle, and specify a Formatter for formattertype;
(6) Policy:Replace Policy + log only policy.
Try
{
//Run code.
}
Catch (Exception ex)
{< br> bool rethrow = exceptionpolicy. handleexception (ex, " * policy " ); // The Exception Handling Policy created above
If (rethrow)
throw ;
}
4. design of exception handling Application Block: