Table of Contents

Class NotFoundException

Namespace
Cuemon.AspNetCore.Http
Assembly
Cuemon.AspNetCore.dll

The exception that is thrown when the server can not find the requested resource.

public class NotFoundException : HttpStatusCodeException, ISerializable
Inheritance
NotFoundException
Implements
Inherited Members

Examples

The following example demonstrates how to use NotFoundException when a requested resource does not exist.

using System;
using Cuemon.AspNetCore.Http;

namespace MyApp.Examples;

public class NotFoundExceptionExample
{
    public void Demonstrate()
    {
        try
        {
            var userId = 999;
            var user = FindUser(userId);
            if (user == null)
            {
                throw new NotFoundException($"User with ID {userId} was not found.");
            }
        }
        catch (NotFoundException ex)
        {
            Console.WriteLine(ex.StatusCode); // 404
            Console.WriteLine(ex.Message);    // User with ID 999 was not found.
        }
    }

    private object FindUser(int id) => null;
}

Constructors

NotFoundException()

Initializes a new instance of the NotFoundException class.

public NotFoundException()

NotFoundException(Exception)

Initializes a new instance of the NotFoundException class.

public NotFoundException(Exception innerException)

Parameters

innerException Exception

The exception that is the cause of the current exception.

NotFoundException(string, Exception)

Initializes a new instance of the NotFoundException class.

public NotFoundException(string message, Exception innerException = null)

Parameters

message string

The message that describes the HTTP status code.

innerException Exception

The exception that is the cause of the current exception.

See Also