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
These docs are for v2.0. Click to read the latest docs for v3.0.

Configure the error handler

You can provide your own custom error handler logic to standardize across your production environment. This error handler is called in the following situations:

  • Unknown experiment key referenced
  • Unknown event key referenced

If the error handler is not overridden, a no-op error handler is used by default.

import com.optimizely.ab.android.sdk.OptimizelyManager;
import com.optimizely.ab.error.ErrorHandler;

// Default handler that raises exceptions
ErrorHandler errorHandler = new RaiseExceptionErrorHandler();

// Build a manager
optimizelyManager = OptimizelyManager.builder()
  .withSDKKey("SDK_KEY_HERE")
  .withEventDispatchInterval(60L * 10L)
  .withErrorHandler(errorHandler)
  .withDatafileDownloadInterval(60L * 10L)
  .build(getApplicationContext());
using OptimizelySDK;
using OptimizelySDK.ErrorHandler;

	var defaultErrorHandler = new DefaultErrorHandler();

	Optimizely optimizelyClient = new Optimizely(
		datafile: datafile,
		errorHandler: defaultErrorHandler);
import com.optimizely.ab.Optimizely;
import com.optimizely.ab.error.ErrorHandler;
import com.optimizely.ab.error.RaiseExceptionErrorHandler;
import com.optimizely.ab.event.AsyncEventHandler;
import com.optimizely.ab.event.EventHandler;

EventHandler eventHandler = new AsyncEventHandler(20000, 1);

// Default handler that raises exceptions
ErrorHandler errorHandler = new RaiseExceptionErrorHandler();

Optimizely optimizelyClient;
try {
    // Create an Optimizely client with the default event dispatcher
    optimizelyClient = Optimizely.builder(datafile, eventHandler)
                           .withErrorHandler(errorHandler)
                           .build();
} catch (ConfigParseException e) {
    // Handle exception gracefully
    return;
}
const defaultErrorHandler = require("@optimizely/optimizely-sdk/lib/plugins/error_handler");

var optimizelyClientWithErrorHandler = optimizely.createInstance({
  datafile,
  errorHandler: defaultErrorHandler
});
/** 
 * Provide your own custom error handler logic by replacing the
 * `errorHandler` property in the `OPTLYManagerBuilder` object
 * during initialization. The error handler you create must 
 * conform to the `OPTLYErrorHandler` protocol. Overriding this
 * module will allow you to standardize error and exception 
 * handling across your application.
 */
CustomErrorHandler *customErrorHandler = [[CustomErrorHandler alloc] init];

    OPTLYManager *manager = [[OPTLYManager alloc] initWithBuilder:[OPTLYManagerBuilder  builderWithBlock:^(OPTLYManagerBuilder * _Nullable builder) {
  builder.sdkKey = @"SDK_KEY_HERE";
  builder.errorHandler = customErrorHandler;
}]];
use Optimizely\ErrorHandler\DefaultErrorHandler;

$optimizelyClient = new Optimizely($datafile, null, null, new DefaultErrorHandler());
from optimizely.error_handler import NoOpErrorHandler as error_handler
from optimizely import optimizely

optimizely_client = optimizely.Optimizely(datafile,
                                          event_dispatcher=event_dispatcher,
                                          logger=logger,
                                          error_handler=error_handler)
optimizely_client = Optimizely::Project.new(datafile,
                                            Optimizely::EventDispatcher.new,
                                            Optimizely::NoOpLogger.new,
                                            Optimizely::NoOpErrorHandler.new)
/**
 *  Provide your own custom error handler logic by replacing 
 *  the `errorHandler` property in the `OPTLYManagerBuilder` 
 *  object during initialization. The error handler you create
 *  must conform to the `OPTLYErrorHandler` protocol.  
 *  Overriding this module will allow you to standardize error
 *  and exception handling across your application.
 */
let customErrorHandler: CustomErrorHandler? = CustomErrorHandler()

let manager = OPTLYManager(builder: OPTLYManagerBuilder(block: { (builder) in
  builder!.sdkKey = "SDK_KEY_HERE"
  builder!.errorHandler = customErrorHandler
}))