The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

SDL2::error - Simple Error Message Routines for SDL

SYNOPSIS

    use SDL2 qw[:error];

DESCRIPTION

Functions in this import tag provide simple error message routines for SDL. SDL_GetError( )|/SDL_GetError( ) >> can be called for almost all SDL functions to determine what problems are occurring. Check the wiki page of each specific SDL function to see whether SDL_GetError( ) is meaningful for them or not. These functions may be imported with the :error tag.

Functions

The SDL error messages are in English.

SDL_SetError( ... )

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

Expected parameters:

fmt

a printf( )-style message format string

@params

additional parameters matching % tokens in the fmt string, if any

SDL_GetError( )

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

        warn SDL_GetError( );

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( ).

SDL_GetErrorMsg( ... )

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

        my $x;
        warn SDL_GetErrorMsg($x, 300);

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

errstr

A buffer to fill with the last error message that was set for the current thread

maxlen

The size of the buffer pointed to by the errstr parameter

Returns the pointer passed in as the errstr parameter.

SDL_ClearError( )

Clear any previous error message for this thread.

    SDL_ClearError( );

SDL_Error( ... )

Set the current error to a member of the <SDL_errorcode enum.

    SDL_Error( SDL_EFWRITE );

Unconditionally returns -1.

Enumerations

These are defined for your use!

SDL_errorcode

These values may be imported with the :errorcode tag.

SDL_ENOMEM - Out of memory
SDL_EFREAD - Error reading file
SDL_EFWRITE - Error writing file
SDL_EFSEEK - Error seeking in file
SDL_UNSUPPORTED
SDL_LASTERROR

LICENSE

Copyright (C) Sanko Robinson.

This library is free software; you can redistribute it and/or modify it under the terms found in the Artistic License 2. Other copyrights, terms, and conditions may apply to data transmitted through this module.

AUTHOR

Sanko Robinson <sanko@cpan.org>