Partager via


How to: Implement Adapter Error Handling

 

Applies To: Windows Server 2012 Essentials

This topic describes how to implement the error handling for a hosted email adapter.

The primary tool for communicating errors with the built-in provider is the HostedEmailAdaptorException. This object contains an ErrorRecord, which contains the details of the exception, as well as a numeric ErrorCode. The recommended pattern of use is to use internal exceptions and events to control the flow of your own assembly, and then to bubble up a HostedEmailAdaptorException to communicate with the provider. These exceptions, in turn, will make their way up through the provider to the UI.

Example

The following example describes how to use a HostedEmailAdaptorException to pass an error event to the provider in an implementation of CreateAccount. For the complete example, see Quickstart: Creating a Hosted Email Adapter.

public EmailAccountInfo CreateAccount(EmailAccountInfo info, string password)  
{  
    try  
    {  
        return EmailService.AddAccount(info);  
    }  
    catch (AccountExistsException)  
    {  
        throw new HostedEmailAdaptorException(HostedEmailAdaptorErrorCode.AccountAlreadyExists, new AddinErrorRecord()  
        {  
            Message = Resources.ErrMsg_OnlineUserAlreadyExist,  
            Title = Resources.ErrTitle_OnlineUserAlreadyExist,  
        });  
    }  
}