Table of Contents

UnsuccessfulValue Class

Definition

Namespace
Cuemon
Assemblies
Cuemon.Kernel.dll
Source
src/Cuemon.Kernel/UnsuccessfulValue.cs

Provides a way to indicate a faulted operation. This class cannot be inherited.

public sealed class UnsuccessfulValue : ConditionalValue
Inheritance
UnsuccessfulValue
Inherited Members

Examples

The following example demonstrates how to use UnsuccessfulValue to represent a void operation that failed with an exception, providing a consistent way to signal failure without throwing.

// Program.cs
using System;
using Cuemon;
using Contoso.Connections;

UnsuccessfulValueExample.Run();

namespace Contoso.Connections
{
    public sealed class UnsuccessfulValueExample
    {
        public static void Run()
        {
            ConditionalValue outcome = OpenConnection(null);

            Console.WriteLine($"Succeeded: {outcome.Succeeded}");
            Console.WriteLine($"Failure: {outcome.Failure?.GetType().Name}");
        }

        private static ConditionalValue OpenConnection(string connectionString)
        {
            try
            {
                Validator.ThrowIfNullOrWhitespace(connectionString);
                return new SuccessfulValue();
            }
            catch (Exception ex)
            {
                return new UnsuccessfulValue(ex);
            }
        }
    }
}

Constructors

Name Description
UnsuccessfulValue(Exception)

Initializes a new instance of the UnsuccessfulValue class.

See Also