Skip to content

Handling errors

Josh Hiles edited this page Dec 22, 2023 · 1 revision

If an exception is thrown in any of Scientist's internal helpers like Compare, Enabled, or Ignore, the default behavior of Scientist is to re-throw that exception. Since this halts the experiment entirely, it's often a better idea to handle this error and continue so the experiment as a whole isn't canceled entirely:

Scientist.Science<int>("ExperimentCatch", experiment =>
{
    experiment.Thrown((operation, exception) => InternalTracker.Track($"Science failure in ExperimentCatch: {operation}.", exception))
    // ...
});

The operations that may be handled here are:

  • Operation.Compare - an exception is raised in a Compare block
  • Operation.Enabled - an exception is raised in the Enabled block
  • Operation.Ignore - an exception is raised in an Ignore block
  • Operation.Publish - an exception is raised while publishing results
  • Operation.RunIf - an exception is raised in a RunIf block