Optimizely will be sunsetting Full Stack Experimentation on July 29, 2024. See the recommended Feature Experimentation migration timeline and documentation.

Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunitySumbit a ticketLog In
GitHubNuGetDev CommunitySumbit a ticket

Customize error handler

How to create your own error handler logic for the Optimizely C# SDK.

You can provide your own custom error handler logic to standardize error messaging across your production environment.

This error handler is called when the C# SDK is not executed as expected. This may be caused by incorrect arguments being provided to the SDK or running the SDK in an environment where network or any other disruptions occur.

See the C# code example. If the error handler is not overridden, a no-op error handler is used by default.

using System;
using OptimizelySDK.ErrorHandler;

/**
 * Creates a CustomErrorHandler and calls HandleError when the SDK raises an exception. 
 *
 * CustomErrorHandler should be inherited by IErrorHandler, namespace of OptimizelySDK.ErrorHandler.
 **/
public class CustomErrorHandler : IErrorHandler
{
    /// <summary>
    /// Handle exceptions when raised by the SDK.
    /// </summary>
    /// <param name="exception">object of Exception raised by the SDK.</param>
    public void HandleError(Exception exception)
    {
        throw new NotImplementedException();
    }
}
using System;
using OptimizelySDK.ErrorHandler;

/**
 * Creates a CustomErrorHandler and calls HandleError when exception is raised by the SDK. 
 **/
/** CustomErrorHandler should be inherited by IErrorHandler, namespace of OptimizelySDK.ErrorHandler.
 **/
public class CustomErrorHandler : IErrorHandler
{
    /// <summary>
    /// Handle exceptions when raised by the SDK.
    /// </summary>
    /// <param name="exception">object of Exception raised by the SDK.</param>
    public void HandleError(Exception exception)
    {
        throw new NotImplementedException();
    }
}