Table of Contents

NotFoundException Class

Definition

Namespace
Cuemon.AspNetCore.Http
Assemblies
Cuemon.AspNetCore.dll
Source
src/Cuemon.AspNetCore/Http/NotFoundException.cs

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.

// Program.cs
using System;
using Cuemon.AspNetCore.Http;
using MyApp.Examples;

new NotFoundExceptionExample().Demonstrate();

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

Name Description
NotFoundException()

Initializes a new instance of the NotFoundException class.

NotFoundException(Exception)

Initializes a new instance of the NotFoundException class.

NotFoundException(string, Exception)

Initializes a new instance of the NotFoundException class.

See Also