Initial commit
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
namespace CeresSharp.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// Base exception for all Ceres-related errors.
|
||||
/// </summary>
|
||||
public class CeresException : Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the error code associated with this exception.
|
||||
/// </summary>
|
||||
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}"
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Error codes returned by Ceres wrapper functions.
|
||||
/// </summary>
|
||||
public enum CeresErrorCode
|
||||
{
|
||||
Success = 0,
|
||||
NullPointer = 1,
|
||||
InvalidParameter = 2,
|
||||
InvalidEnum = 3,
|
||||
Exception = 4,
|
||||
OutOfMemory = 5,
|
||||
InvalidOperation = 6,
|
||||
BufferTooSmall = 7,
|
||||
NotFound = 8,
|
||||
AlreadyExists = 9
|
||||
}
|
||||
Reference in New Issue
Block a user