namespace Brutal.SdlApi;
///
/// The exception thrown when an SDL call fails. Its carries the
/// human-readable error text SDL reported through SDL_GetError at the point of failure.
///
public class SdlException : Exception
{
///
/// Initializes a new with the given message.
///
/// The failure description, typically the SDL_GetError text.
public SdlException(string message)
: base(message) { }
///
/// Initializes a new with the given message and inner exception.
///
/// The failure description, typically the SDL_GetError text.
/// The underlying exception that caused this failure.
public SdlException(string message, Exception innerException)
: base(message, innerException) { }
///
/// Creates an whose message is the current SDL_GetError text,
/// copied immediately into managed memory (SDL owns the returned pointer). The
/// prefixes the SDL message so the failing operation is identifiable.
///
/// A short description of the operation that failed.
/// A new carrying and the SDL error text.
public static SdlException FromError(string context)
{
var error = Sdl.PInvoke.GetError();
return string.IsNullOrEmpty(error) ? new SdlException(context) : new SdlException($"{context}: {error}");
}
}