Table of Contents

Class UniqueIndexViolationException

Namespace
Cuemon.Data
Assembly
Cuemon.Data.dll

The exception that is thrown when a unique index violation occurs from a data source.

public class UniqueIndexViolationException : Exception, ISerializable
Inheritance
UniqueIndexViolationException
Implements
Inherited Members

Examples

UniqueIndexViolationException represents a unique index or constraint violation error, with support for inner exceptions and parameterless construction. This example throws a new instance with a descriptive message about a duplicate key in dbo.Users and catches it to print the message. It also creates a wrapped exception with an inner InvalidOperationException as the cause, and demonstrates the default parameterless constructor with type name resolution via GetType().Name. Console output shows the exception messages and the resolved type name UniqueIndexViolationException.

using System;
using Cuemon.Data;

namespace MyApp.Data
{
    public sealed class UniqueIndexViolationExceptionExample
    {
        public void Demonstrate()
        {
            try
            {
                throw new UniqueIndexViolationException("Cannot insert duplicate key row in object 'dbo.Users'.");
            }
            catch (UniqueIndexViolationException ex)
            {
                Console.WriteLine(ex.Message);
            }

            var wrapped = new UniqueIndexViolationException(
                "Failed to register user.",
                new InvalidOperationException("IX_Users_Email was violated."));

            Console.WriteLine(wrapped.Message);
            Console.WriteLine(wrapped.InnerException?.Message);

            var empty = new UniqueIndexViolationException();
            Console.WriteLine(empty.GetType().Name);
        }
    }
}

Constructors

UniqueIndexViolationException()

Initializes a new instance of the UniqueIndexViolationException class.

public UniqueIndexViolationException()

UniqueIndexViolationException(string)

Initializes a new instance of the UniqueIndexViolationException class.

public UniqueIndexViolationException(string message)

Parameters

message string

The message that describes the error.

UniqueIndexViolationException(string, Exception)

Initializes a new instance of the UniqueIndexViolationException class.

public UniqueIndexViolationException(string message, Exception innerException)

Parameters

message string

The message that describes the error.

innerException Exception

The exception that is the cause of the current exception. If the innerException parameter is not a null reference, the current exception is raised in a catch block that handles the inner exception.