Table of Contents

Class ExceptionInvoker<TException>

Namespace
Cuemon
Assembly
Cuemon.Kernel.dll

Provides a generic way to throw an Exception.

public class ExceptionInvoker<TException> where TException : Exception

Type Parameters

TException

The type of the Exception.

Inheritance
ExceptionInvoker<TException>

Examples

The following example demonstrates the shared workflow for the family: evaluate a business condition, build the invoker from that condition, and call TryThrow() when the invalid state should surface as an exception.

using System;
using System.Collections.Generic;
using Cuemon;

namespace MyApp.Examples;

public static class ExceptionInvokerExample
{
    public static void Demonstrate()
    {
        var settings = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

        ExceptionInvoker<InvalidOperationException> invoker =
            new ExceptionCondition<InvalidOperationException>()
                .IsTrue(() => !settings.ContainsKey("ConnectionString"))
                .Create(() => new InvalidOperationException("A ConnectionString setting is required before the data pipeline can start."));

        bool threw = false;

        try
        {
            invoker.TryThrow();
        }
        catch (InvalidOperationException ex)
        {
            threw = true;
            Console.WriteLine(ex.Message);
        }

        Console.WriteLine($"Threw: {threw}");
    }
}

Methods

TryThrow()

Determines whether an Exception of type TException should be thrown.

public void TryThrow()