Table of Contents

ExceptionDescriptor Class

Definition

Namespace
Cuemon.Diagnostics
Assemblies
Cuemon.Core.dll
Source
src/Cuemon.Core/Diagnostics/ExceptionDescriptor.cs

Provides information about an Exception, in a developer friendly way.

public class ExceptionDescriptor
Inheritance
ExceptionDescriptor

Examples

The following example demonstrates how to create and enrich it with contextual evidence.

using System;
using Cuemon.Diagnostics;

namespace MyApp.Examples;

public static class ExceptionDescriptorExample
{
    public static void Demonstrate()
    {
        var descriptor = new ExceptionDescriptor(
            new InvalidOperationException("Order 12345 has already been processed."),
            code: "OrderAlreadyProcessed",
            message: "The order cannot be modified because it has already been processed.",
            helpLink: new Uri("https://docs.example.com/errors/order-already-processed"));

        descriptor.AddEvidence("OrderId", 12345, value => value);
        descriptor.AddEvidence("UserId", "alice@example.com", value => value);

        Console.WriteLine(descriptor.Code);
        Console.WriteLine(descriptor.Message);
        Console.WriteLine(descriptor.Evidence.Count);
    }
}

Constructors

Name Description
ExceptionDescriptor()

Initializes a new instance of the ExceptionDescriptor class.

ExceptionDescriptor(Exception, string, string, Uri)

Initializes a new instance of the ExceptionDescriptor class.

Properties

Name Description
Code

Gets an error code that uniquely identifies the type of failure.

Evidence

Gets a collection of key/value pairs that can provide additional information about the failure.

Failure

Gets the Exception that caused the current failure.

HelpLink

Gets or sets a link to the help page associated with this failure.

Message

Gets a message that describes the current failure.

Methods

Name Description
AddEvidence<T>(string, T, Func<T, object>)

Adds an element of evidence to associate with the faulted operation.

Extract(Exception, string, string, Uri)

Converts the specified exception to a developer friendly ExceptionDescriptor.

PostInitializeWith(ExceptionDescriptorAttribute)

Post initialize this instance with the specified attribute.

PostInitializeWith(IEnumerable<ExceptionDescriptorAttribute>)

Post initialize this instance with a matching ExceptionDescriptorAttribute from the specified attributes.

ToString()

Returns a string that represents this instance.