sdl2.ext.err - Handling & Raising SDL Errors¶
This module defines a Python exception class for representing internal SDL2 errors, as well as convenience functions for cleanly handling and raising SDL errors in Python code.
-
exception
sdl2.ext.err.
SDLError
(msg=None)[source]¶ A custom exception class for SDL2-specific errors.
Parameters: msg (str, optional) – The error message for the exception. If not provided, the current SDL error (if any) will be retrieved using :func:~sdl2.SDL_GetError.
-
sdl2.ext.err.
raise_sdl_err
(desc=None)[source]¶ Raises an exception for an internal SDL error.
The format of the exception message depends on whether a description is provided and whether :func:~sdl2.SDL_GetError returns an error string. If a description is given, it will be appended after the default text
Error encountered
. If SDL has set an error string, it will be appended to the end of the message following a colon (clearing the error in the process).For example, if
SDL_GetError() == b"unsupported pixel format"
and the function is called asraise_sdl_err("creating the surface")
, the resulting exception message will be “Error encountered creating the surface: unsupported pixel format”.Parameters: desc (str. optional) – A description of what SDL was trying to do when the error occurred. Will be placed after the text “Error encountered” in the exception message if provided. Raises: SDLError
– An exception explaining the most recent SDL error.