Table of Contents

Class ResourceNotFoundException

Namespace
Excalibur.Data
Assembly
Excalibur.Data.Abstractions.dll

Exception thrown when a requested resource cannot be found.

public sealed class ResourceNotFoundException : ResourceException, ISerializable
Inheritance
ResourceNotFoundException
Implements
Inherited Members

Examples

var user = await repository.FindByIdAsync(userId, cancellationToken)
    ?? throw new ResourceNotFoundException("User", userId.ToString());

Remarks

This exception indicates that a specific resource (entity, record, or object) does not exist or could not be located. It maps to HTTP status code 404 (Not Found).

Use this exception when:

  • Looking up an entity by ID that doesn't exist
  • Attempting to access a resource that has been deleted
  • Querying for a record that doesn't match any criteria

Constructors

ResourceNotFoundException()

Initializes a new instance of the ResourceNotFoundException class.

public ResourceNotFoundException()

ResourceNotFoundException(string)

Initializes a new instance of the ResourceNotFoundException class with a specified error message.

public ResourceNotFoundException(string message)

Parameters

message string

The error message that explains the reason for the exception.

ResourceNotFoundException(string, Exception?)

Initializes a new instance of the ResourceNotFoundException class with a message and inner exception.

public ResourceNotFoundException(string message, Exception? innerException)

Parameters

message string

The error message that explains the reason for the exception.

innerException Exception

The exception that is the cause of the current exception.

ResourceNotFoundException(string, string?)

Initializes a new instance of the ResourceNotFoundException class with resource information.

public ResourceNotFoundException(string resource, string? resourceId)

Parameters

resource string

The type or name of the resource that was not found.

resourceId string

The optional identifier of the resource that was not found.

Methods

ForEntity<TEntity>(object)

Creates a ResourceNotFoundException for a specific entity type and ID.

public static ResourceNotFoundException ForEntity<TEntity>(object id)

Parameters

id object

The identifier of the entity.

Returns

ResourceNotFoundException

A new ResourceNotFoundException instance.

Type Parameters

TEntity

The type of the entity.