SDL  2.0
SDL_error.h File Reference
#include "SDL_stdinc.h"
#include "begin_code.h"
#include "close_code.h"
+ 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.

Functions

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

Internal error functions

Private error reporting function - used internally.

#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
}
 
int SDL_Error (SDL_errorcode code)
 

Detailed Description

Simple error message routines for SDL.

Definition in file SDL_error.h.

Macro Definition Documentation

◆ SDL_InvalidParamError

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

Definition at line 141 of file SDL_error.h.

◆ SDL_OutOfMemory

#define SDL_OutOfMemory ( )    SDL_Error(SDL_ENOMEM)

Definition at line 139 of file SDL_error.h.

◆ SDL_Unsupported

#define SDL_Unsupported ( )    SDL_Error(SDL_UNSUPPORTED)

Definition at line 140 of file SDL_error.h.

Enumeration Type Documentation

◆ SDL_errorcode

Enumerator
SDL_ENOMEM 
SDL_EFREAD 
SDL_EFWRITE 
SDL_EFSEEK 
SDL_UNSUPPORTED 
SDL_LASTERROR 

Definition at line 142 of file SDL_error.h.

143 {
144  SDL_ENOMEM,
145  SDL_EFREAD,
146  SDL_EFWRITE,
147  SDL_EFSEEK,
150 } SDL_errorcode;
SDL_errorcode
Definition: SDL_error.h:143
@ SDL_EFSEEK
Definition: SDL_error.h:147
@ SDL_LASTERROR
Definition: SDL_error.h:149
@ SDL_EFWRITE
Definition: SDL_error.h:146
@ SDL_UNSUPPORTED
Definition: SDL_error.h:148
@ SDL_EFREAD
Definition: SDL_error.h:145
@ SDL_ENOMEM
Definition: SDL_error.h:144

Function Documentation

◆ SDL_ClearError()

void 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_Error()

int SDL_Error ( SDL_errorcode  code)

◆ SDL_GetError()

const char* 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()

char* 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()

int 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);
}
int 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