My Project
Loading...
Searching...
No Matches
SDL_error.h File Reference
#include "SDL_stdinc.h"
#include "begin_code.h"
#include "close_code.h"

Go to the source code of this file.

Functions

DECLSPEC int SDLCALL SDL_SetError (SDL_PRINTF_FORMAT_STRING const char *fmt,...) SDL_PRINTF_VARARG_FUNC(1)
 
DECLSPEC const char *SDLCALL SDL_GetError (void)
 
DECLSPEC char *SDLCALL SDL_GetErrorMsg (char *errstr, int maxlen)
 
DECLSPEC void SDLCALL SDL_ClearError (void)
 

Internal error functions

#define SDL_OutOfMemory()   SDL_Error(SDL_ENOMEM)
 
#define SDL_Unsupported()   SDL_Error(SDL_UNSUPPORTED)
 
#define SDL_InvalidParamError(param)   SDL_SetError("Parameter '%s' is invalid", (param))
 
enum  SDL_errorcode {
  SDL_ENOMEM , SDL_EFREAD , SDL_EFWRITE , SDL_EFSEEK ,
  SDL_UNSUPPORTED , SDL_LASTERROR
}
 
DECLSPEC int SDLCALL SDL_Error (SDL_errorcode code)
 

Detailed Description

Simple error message routines for SDL.

Function Documentation

◆ SDL_ClearError()

DECLSPEC void SDLCALL SDL_ClearError ( void  )

Clear any previous error message for this thread.

Since
This function is available since SDL 2.0.0.
See also
SDL_GetError
SDL_SetError

◆ SDL_GetError()

DECLSPEC const char *SDLCALL SDL_GetError ( void  )

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 string is internally allocated and must not be freed by the application.

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(). 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().
Since
This function is available since SDL 2.0.0.
See also
SDL_ClearError
SDL_SetError

◆ SDL_GetErrorMsg()

DECLSPEC char *SDLCALL SDL_GetErrorMsg ( char *  errstr,
int  maxlen 
)

Get the last error message that was set for the current thread.

This allows the caller to copy the error string into a provided buffer, but otherwise operates exactly the same as SDL_GetError().

Parameters
errstrA buffer to fill with the last error message that was set for the current thread
maxlenThe size of the buffer pointed to by the errstr parameter
Returns
the pointer passed in as the errstr parameter.
Since
This function is available since SDL 2.0.14.
See also
SDL_GetError

◆ SDL_SetError()

DECLSPEC int SDLCALL SDL_SetError ( SDL_PRINTF_FORMAT_STRING const char *  fmt,
  ... 
)

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 -1, since SDL frequently uses -1 to signify an failing result, leading to this idiom:

if (error_code) {
return SDL_SetError("This operation has failed: %d", error_code);
}
DECLSPEC int SDLCALL SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt,...) SDL_PRINTF_VARARG_FUNC(1)
Parameters
fmta printf()-style message format string
...additional parameters matching % tokens in the fmt string, if any
Returns
always -1.
Since
This function is available since SDL 2.0.0.
See also
SDL_ClearError
SDL_GetError