using System;
namespace ZB.MOM.WW.CBDDC.Core.Exceptions;
///
/// Base exception for all CBDDC-related errors.
///
public class CBDDCException : Exception
{
///
/// Error code for programmatic error handling.
///
public string ErrorCode { get; }
///
/// Initializes a new instance of the class.
///
/// The application-specific error code.
/// The exception message.
public CBDDCException(string errorCode, string message)
: base(message)
{
ErrorCode = errorCode;
}
///
/// Initializes a new instance of the class.
///
/// The application-specific error code.
/// The exception message.
/// The exception that caused the current exception.
public CBDDCException(string errorCode, string message, Exception innerException)
: base(message, innerException)
{
ErrorCode = errorCode;
}
}
///
/// Exception thrown when network operations fail.
///
public class NetworkException : CBDDCException
{
///
/// Initializes a new instance of the class.
///
/// The exception message.
public NetworkException(string message)
: base("NETWORK_ERROR", message) { }
///
/// Initializes a new instance of the class.
///
/// The exception message.
/// The exception that caused the current exception.
public NetworkException(string message, Exception innerException)
: base("NETWORK_ERROR", message, innerException) { }
}
///
/// Exception thrown when persistence operations fail.
///
public class PersistenceException : CBDDCException
{
///
/// Initializes a new instance of the class.
///
/// The exception message.
public PersistenceException(string message)
: base("PERSISTENCE_ERROR", message) { }
///
/// Initializes a new instance of the class.
///
/// The exception message.
/// The exception that caused the current exception.
public PersistenceException(string message, Exception innerException)
: base("PERSISTENCE_ERROR", message, innerException) { }
}
///
/// Exception thrown when synchronization operations fail.
///
public class SyncException : CBDDCException
{
///
/// Initializes a new instance of the class.
///
/// The exception message.
public SyncException(string message)
: base("SYNC_ERROR", message) { }
///
/// Initializes a new instance of the class.
///
/// The exception message.
/// The exception that caused the current exception.
public SyncException(string message, Exception innerException)
: base("SYNC_ERROR", message, innerException) { }
}
///
/// Exception thrown when configuration is invalid.
///
public class ConfigurationException : CBDDCException
{
///
/// Initializes a new instance of the class.
///
/// The exception message.
public ConfigurationException(string message)
: base("CONFIG_ERROR", message) { }
}
///
/// Exception thrown when database corruption is detected.
///
public class DatabaseCorruptionException : PersistenceException
{
///
/// Initializes a new instance of the class.
///
/// The exception message.
public DatabaseCorruptionException(string message)
: base(message) { }
///
/// Initializes a new instance of the class.
///
/// The exception message.
/// The exception that caused the current exception.
public DatabaseCorruptionException(string message, Exception innerException)
: base(message, innerException) { }
}
///
/// Exception thrown when a timeout occurs.
///
public class TimeoutException : CBDDCException
{
///
/// Initializes a new instance of the class.
///
/// The operation that timed out.
/// The timeout in milliseconds.
public TimeoutException(string operation, int timeoutMs)
: base("TIMEOUT_ERROR", $"Operation '{operation}' timed out after {timeoutMs}ms") { }
}
///
/// Exception thrown when a document is not found in a collection.
///
public class DocumentNotFoundException : PersistenceException
{
///
/// Gets the document key that was not found.
///
public string Key { get; }
///
/// Gets the collection where the document was searched.
///
public string Collection { get; }
///
/// Initializes a new instance of the class.
///
/// The collection where the document was searched.
/// The document key that was not found.
public DocumentNotFoundException(string collection, string key)
: base($"Document with key '{key}' not found in collection '{collection}'.")
{
Collection = collection;
Key = key;
}
}
///
/// Exception thrown when a concurrency conflict occurs during persistence operations.
///
public class CBDDCConcurrencyException : PersistenceException
{
///
/// Initializes a new instance of the class.
///
/// The exception message.
public CBDDCConcurrencyException(string message) : base(message) { }
}