ToolSettings.

HandleExitCode Property

Summary

Gets or sets whether the exit code from the tool process causes an exception to be thrown.

If the delegate is null (the default) or returns false, then an exception is thrown upon a non-zero exit code.

If the delegate returns true then no exception is thrown.

This can be useful when the exit code should be ignored, or if there is a desire to apply logic that is conditional on the exit code value.

Namespace
Cake.Core.Tooling
Containing Type
ToolSettings

Syntax

public Func<int, bool> HandleExitCode { get; set; }

Examples

Don't throw exceptions if DotNetCoreTest returns non-zero:
DotNetCoreTest("MyProject.csproj", new DotNetCoreTestSettings {
    HandleExitCode = _=> true
});
Use custom logic for exit code:
DotNetCoreTest("MyProject.csproj", new DotNetCoreTestSettings {
    HandleExitCode = exitCode => exitCode switch {
        0 => throw new CakeException("ZERO"),
        1 => true, // treat 1 and 2 as handled "ok".
        2 => true,
        _ => false // everything else will throw via default implementation
    };
});

Value

Type Description
Func<int, bool>