Table of Contents

ExceptionHandler<TException, TResult> Class

Definition

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

Provides a generic way to handle an Exception.

public class ExceptionHandler<TException, TResult> where TException : Exception

Type Parameters

TException

The type of the Exception.

TResult

The type of the out result value of a TesterFunc<TResult, TSuccess>.

Inheritance
ExceptionHandler<TException, TResult>

Examples

The following example demonstrates how to use the generic class in the fluent exception-triggering chain with an out-value (tester) condition.

// Program.cs
using System;
using Cuemon;

TesterFunc<int, bool> parsePort = (out int value) => int.TryParse("70000", out value);

ExceptionHandler<ArgumentOutOfRangeException, int> handler =
    new ExceptionCondition<ArgumentOutOfRangeException>().IsTrue(parsePort);

var invoker = handler.Create(port =>
    new ArgumentOutOfRangeException(nameof(port), port, "Ports must be between 0 and 65535."));

try
{
    invoker.TryThrow();
}
catch (ArgumentOutOfRangeException ex)
{
    Console.WriteLine($"Rejected port: {ex.ActualValue}");
}

Methods

Name Description
Create(Func<TResult, TException>)

Specifies the function delegate that determines the Exception to be thrown.