Class Error
- Namespace
- Sdl3Sharp
- Assembly
- Sdl3Sharp.dll
Provides simple error message routines for SDL
public static class Error
- Inheritance
-
Error
- Inherited Members
Methods
Clear()
Clears any previous error message for this thread
public static bool Clear()
Returns
OutOfMemory()
Sets an error indicating that memory allocation failed
public static bool OutOfMemory()
Returns
Remarks
This method does not do any memory allocation on the native side.
Set(string)
Sets the SDL error message for the current thread
public static bool Set(string message)
Parameters
messagestringThe error message to be set
Returns
Examples
This method always returns false; since SDL frequently uses false to signify a failing result, this leads to the following idiom:
if (/* condition indicating an error */)
{
return Error.Set("Error message example");
}
Remarks
Calling this method will replace any previous error message that was set for this thread.
Set(string, params ReadOnlySpan<object>)
Sets the SDL error message to a format string for the current thread
public static bool Set(string format, params ReadOnlySpan<object> args)
Parameters
formatstringThe C-style
printfformat stringargsReadOnlySpan<object>The arguments corresponding to the format specifiers in
format
Returns
Examples
This method always returns false; since SDL frequently uses false to signify a failing result, this leads to the following idiom:
if (/* condition indicating an error */)
{
return Error.Set("%s", "Error message example");
}
Remarks
Calling this method will replace any previous error message that was set for this thread.
The format parameter is interpreted as a C-style printf format string, and
the args parameter supplies the values for its format specifiers. Supported argument
types include all integral types up to 64-bit (including bool and char),
floating point types (float and double), pointer types
(nint and nuint), and string.
For a detailed explanation of C-style printf format strings and their specifiers, see
https://en.wikipedia.org/wiki/Printf#Format_specifier.
Consider using Set(string) instead when possible, as it may be more efficient. In many cases, you can use C# string interpolation to construct the message before logging.
TryGet(out string?)
Tries to retrieve a message about the last error that occurred on the current thread
public static bool TryGet(out string? message)
Parameters
messagestringA message with information about the specific error that occurred, or
nullif there hasn't been an error message set since the last call to Clear()
Returns
Remarks
It is possible for multiple errors to occur before calling TryGet(out string?). Only the last error is returned.
The message is only applicable when an SDL has signaled an error. You must check the return values of SDL calls to determine when to appropriately call TryGet(out string?). You should not use the result of TryGet(out string?) to decide if an error has occurred! Sometimes SDL will set an error string even when reporting success.
SDL will not clear the error message for successful API calls. You must check for failure cases before you can assume the error message applies.
Error messages are set per-thread, so an error set in a different thread will not interfere with the current thread's operation.