SDL 3.0
SDL_error.h File Reference
+ Include dependency graph for SDL_error.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

Internal error functions

Private error reporting function - used internally.

#define SDL_Unsupported()   SDL_SetError("That operation is not supported")
 
#define SDL_InvalidParamError(param)   SDL_SetError("Parameter '%s' is invalid", (param))
 

Functions

bool SDL_SetError (SDL_PRINTF_FORMAT_STRING const char *fmt,...) SDL_PRINTF_VARARG_FUNC(1)
 
bool SDL_OutOfMemory (void)
 
const char * SDL_GetError (void)
 
bool SDL_ClearError (void)
 

Macro Definition Documentation

◆ SDL_InvalidParamError

#define SDL_InvalidParamError (   param)    SDL_SetError("Parameter '%s' is invalid", (param))

Definition at line 154 of file SDL_error.h.

◆ SDL_Unsupported

#define SDL_Unsupported ( )    SDL_SetError("That operation is not supported")

Definition at line 153 of file SDL_error.h.

Function Documentation

◆ SDL_ClearError()

bool SDL_ClearError ( void  )
extern

Clear any previous error message for this thread.

Returns
true.
Since
This function is available since SDL 3.0.0.
See also
SDL_GetError
SDL_SetError

◆ SDL_GetError()

const char * SDL_GetError ( void  )
extern

Retrieve a message about the last error that occurred on the current thread.

It is possible for multiple errors to occur before calling SDL_GetError(). Only the last error is returned.

The message is only applicable when an SDL function has signaled an error. You must check the return values of SDL function calls to determine when to appropriately call SDL_GetError(). You should not use the results of SDL_GetError() to decide if an error has occurred! Sometimes SDL will set an error string even when reporting success.

SDL will not clear the error string for successful API calls. You must check return values for failure cases before you can assume the error string applies.

Error strings are set per-thread, so an error set in a different thread will not interfere with the current thread's operation.

The returned value is a thread-local string which will remain valid until the current thread's error string is changed. The caller should make a copy if the value is needed after the next SDL API call.

Returns
a message with information about the specific error that occurred, or an empty string if there hasn't been an error message set since the last call to SDL_ClearError().
Since
This function is available since SDL 3.0.0.
See also
SDL_ClearError
SDL_SetError

◆ SDL_OutOfMemory()

bool SDL_OutOfMemory ( void  )
extern

Set an error indicating that memory allocation failed.

This function does not do any memory allocation.

Returns
false.
Since
This function is available since SDL 3.0.0.

◆ SDL_SetError()

bool SDL_SetError ( SDL_PRINTF_FORMAT_STRING const char *  fmt,
  ... 
)
extern

CategoryError

Simple error message routines for SDL.

Most apps will interface with these APIs in exactly one function: when almost any SDL function call reports failure, you can get a human-readable string of the problem from SDL_GetError().

These strings are maintained per-thread, and apps are welcome to set their own errors, which is popular when building libraries on top of SDL for other apps to consume. These strings are set by calling SDL_SetError().

A common usage pattern is to have a function that returns true for success and false for failure, and do this when something fails:

if (something_went_wrong) {
return SDL_SetError("The thing broke in this specific way: %d", errcode);
}
bool SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt,...) SDL_PRINTF_VARARG_FUNC(1)

It's also common to just return false in this case if the failing thing is known to call SDL_SetError(), so errors simply propagate through. Set the SDL error message for the current thread.

Calling this function will replace any previous error message that was set.

This function always returns false, since SDL frequently uses false to signify a failing result, leading to this idiom:

if (error_code) {
return SDL_SetError("This operation has failed: %d", error_code);
}
Parameters
fmta printf()-style message format string.
...additional parameters matching % tokens in the fmt string, if any.
Returns
false.
Since
This function is available since SDL 3.0.0.
See also
SDL_ClearError
SDL_GetError