ResultExtensionsErr Method

Overload List

Err(String) Creates a result as the Err variant; with the given error information: errorMessage.
C#
static Res AddUser(User user)
{
    if (AlreadyExists(user))
        return Err($"user '{user.Id}' already exists.");
    if (HasAvailableCapacity(session))
        return Err("not enough capacity");
    else
    {
        // add user
        return Ok();
    }
}
Err(String, Exception) Creates a result as the Err variant; with the given error information: when, exception.
C#
static Res PutItem(Item item)
{
    try
    {
        PutItemToDatabase(item);
        return Ok();
    }
    catch (Exception e)
    {
        return Err(nameof(PutItem), e);
    }
}
Err(String, String) Creates a result as the Err variant; with the given error information: errorMessage, when.
Err(String, String, Exception) Creates a result as the Err variant; with the given error information: errorMessage, when, exception.
C#
static Res PutItem(Item item)
{
    try
    {
        PutItemToDatabase(item);
        return Ok();
    }
    catch (Exception e)
    {
        return Err("failed to execute sql command.", nameof(PutItem), e);
    }
}
ErrT(String) Creates a result of T as Err with the given errorMessage.
C#
static Res<double> Divide(double number, double divider)
{
    if (divider == 0)
        return Err<double>("Cannot divide to zero");
    else
        return Ok(number / divider);
}
ErrT(String, String) Creates a result of T as Err with the given errorMessage which is observed during when.

See Also