Creating Custom Exception Handlers

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

To be able to detect and react to exceptions, developers must provide an exception handler. This exception handler can subscribe to a single type of exception message or to exception messages generated from some or all parts of a system or an application. For example, you may require only a single handler for all messages from a particular system (such as any exceptions occurring in the payroll system), or you may instead require targeted handlers for specific failures (such as detecting if the check print process fails).

To subscribe to a specific type of exception, you may use an orchestration that has a filter on the activating Receive shape of the following:

Microsoft.Practices.ESB.ExceptionHandling.Schemas.Property.FaultCode == "1000";

You may also have a filter condition on a send port that sends messages to the file system or by e-mail if they meet a specific filter condition.

Sample Exception Handling Projects

The Microsoft ESB Guidance package contains several sample BizTalk applications in the \Source\Samples\Exception Handling** **folder that demonstrate exception handling.

There are also four BizTalk projects located in the solution GlobalBank.ESB.Samples.ExceptionHandling** that demonstrate how you can use the ESB Failed Orchestration Exception Routing mechanism. All the projects are preconfigured to deploy into the GlobalBank.ESB **BizTalk application. The projects are the following:

  • ESB.ExceptionHandling.Schemas. This project contains the schemas used for the sample orchestrations.

  • ESB.ExceptionHandling.Pipelines. This project contains the send pipeline configured with the exception processor, used in a send port that subscribes to all exceptions. This includes exceptions generated by BizTalk and exceptions generated by the Exception Management Framework.

  • ESB.ExceptionHandling.Processes. This project contains the EAIProcess.odx orchestration. It simulates an exception by attempting to divide by zero and calls the CreateFaultMessage and AddMessage methods to generate a suitable fault message, as shown in Figure 1.

    Ff650570.e7a422b3-e429-4881-a13c-edb4c14f758b(en-us,PandP.10).png

    Figure 1
    The EAIProcess.odx orchestration in the Processes sample project

  • ESB.ExceptionHandling.Handlers. This project contains the** **EAIGenericHandler.odx orchestration, which calls the GetMessages method and iterates through the MessageCollection using the MoveNext method, as shown in Figure 2.

    Ff650570.e803b94c-c58b-4e8f-a003-9c31fda73e12(en-us,PandP.10).png

    Figure 2
    The EAIGenericHandler.odx orchestration in the Handlers sample project

  • The ESB.ExceptionHandling.Handlers** **project also contains the EAIProcessHandler.odx orchestration, which calls the GetMessage and GetException methods, as shown in Figure 3.

    Ff650570.36389d41-3e6f-45df-8104-70ff82e55429(en-us,PandP.10).png

    Figure 3
    The EAIProcessHandler.odx orchestration in the Handlers sample project