Class SdlError
- java.lang.Object
-
- io.github.libsdl4j.api.error.SdlError
-
public final class SdlError extends Object
Definitions from file SDL_error.hSimple error message routines for SDL.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
SDL_ClearError()
Clear any previous error message for this thread.static String
SDL_GetError()
Retrieve a message about the last error that occurred on the current thread.static com.sun.jna.Pointer
SDL_GetErrorMsg(com.sun.jna.Pointer errstr, int maxlen)
Get the last error message that was set for the current thread.static int
SDL_SetError(String fmt, Object... args)
Set the SDL error message for the current thread.static int
SDL_SetError(Locale lang, String fmt, Object... args)
Set the SDL error message for the current thread.
-
-
-
Method Detail
-
SDL_SetError
public static int SDL_SetError(String fmt, Object... args)
Set the SDL error message for the current thread.Calling this function will replace any previous error message that was set.
In general, this functions is here just in case you wanted to inject an error message to the regular SDL error processing pipeline. Normally, it should not be used. Java's Exceptions should be used instead.
The
fmt
argument is a String with format compatible with Java-styleprintf()
(more preciselyFormatter
,String.format()
orSystem.out.printf()
). Note that it is very similar to the original C-styleprintf()
but has some differences. The formatting is performed in Java prior to the actual SDL call and only pure strings are passed to the SDL library.Locale used for formatting is the default system locale.
This function always returns -1, since SDL frequently uses -1 to signify an failing result. However this is of a very limited use in Java, as it uses Exceptions to report errors.
- Parameters:
fmt
- a Java-style printf() message format stringargs
- additional parameters matching%
tokens in thefmt
string, if any- Returns:
- always -1.
- See Also:
SDL_ClearError()
,SDL_GetError()
-
SDL_SetError
public static int SDL_SetError(Locale lang, String fmt, Object... args)
Set the SDL error message for the current thread.Calling this function will replace any previous error message that was set.
In general, this functions is here just in case you wanted to inject an error message to the regular SDL error processing pipeline. Normally, it should not be used. Java's Exceptions should be used instead.
The
fmt
argument is a String with format compatible with Java-styleprintf()
(more preciselyFormatter
,String.format()
orSystem.out.printf()
). Note that it is very similar to the original C-styleprintf()
but has some differences. The formatting is performed in Java prior to the actual SDL call and only pure strings are passed to the SDL library.This function always returns -1, since SDL frequently uses -1 to signify an failing result. However this is of a very limited use in Java, as it uses Exceptions to report errors.
- Parameters:
lang
- ajava.util.Locale
used to format the argumentsfmt
- a Java-style printf() message format stringargs
- additional parameters matching%
tokens in thefmt
string, if any- Returns:
- always -1.
- See Also:
SDL_ClearError()
,SDL_GetError()
-
SDL_GetError
public static String SDL_GetError()
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(String, Object...)
-
SDL_GetErrorMsg
public static com.sun.jna.Pointer SDL_GetErrorMsg(com.sun.jna.Pointer 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().
This is a raw C-style version of the function. Prefer Java-style version
SDL_GetError()
.- Parameters:
errstr
- A buffer to fill with the last error message that was set for the current threadmaxlen
- The 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_ClearError
public static void SDL_ClearError()
Clear any previous error message for this thread.- Since:
- This function is available since SDL 2.0.0.
- See Also:
SDL_GetError()
,SDL_SetError(String, Object...)
-
-