Class UnsuccessfulValue
- Namespace
- Cuemon
- Assembly
- Cuemon.Kernel.dll
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.
using System;
using Cuemon;
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
UnsuccessfulValue(Exception)
Initializes a new instance of the UnsuccessfulValue class.
public UnsuccessfulValue(Exception failure = null)