namespace CeresSharp.Exceptions;
///
/// Base exception for all Ceres-related errors.
///
public class CeresException : Exception
{
///
/// Gets the error code associated with this exception.
///
public CeresErrorCode ErrorCode { get; }
public CeresException(CeresErrorCode errorCode, string? message = null)
: base(message ?? GetDefaultMessage(errorCode))
{
ErrorCode = errorCode;
}
public CeresException(CeresErrorCode errorCode, string? message, Exception? innerException)
: base(message ?? GetDefaultMessage(errorCode), innerException)
{
ErrorCode = errorCode;
}
private static string GetDefaultMessage(CeresErrorCode errorCode) => errorCode switch
{
CeresErrorCode.Success => "Operation succeeded",
CeresErrorCode.NullPointer => "Null pointer argument",
CeresErrorCode.InvalidParameter => "Invalid parameter value",
CeresErrorCode.InvalidEnum => "Invalid enum value",
CeresErrorCode.Exception => "C++ exception occurred",
CeresErrorCode.OutOfMemory => "Memory allocation failed",
CeresErrorCode.InvalidOperation => "Invalid operation for current state",
CeresErrorCode.BufferTooSmall => "Output buffer too small",
CeresErrorCode.NotFound => "Resource not found",
CeresErrorCode.AlreadyExists => "Resource already exists",
_ => $"Unknown error code: {errorCode}"
};
}
///
/// Error codes returned by Ceres wrapper functions.
///
public enum CeresErrorCode
{
Success = 0,
NullPointer = 1,
InvalidParameter = 2,
InvalidEnum = 3,
Exception = 4,
OutOfMemory = 5,
InvalidOperation = 6,
BufferTooSmall = 7,
NotFound = 8,
AlreadyExists = 9
}