Table of Contents

ExceptionInvoker<TException> Class

Definition

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

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.

// Program.cs
using System;
using System.Collections.Generic;
using Cuemon;

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

Name Description
TryThrow()

Determines whether an Exception of type TException should be thrown.