libSDL2pp
C++ bindings/wrapper for SDL2
Loading...
Searching...
No Matches
Public Member Functions | List of all members
SDL2pp::Exception Class Reference

Exception object representing SDL2 error More...

#include <SDL2pp/Exception.hh>

Inheritance diagram for SDL2pp::Exception:

Public Member Functions

 Exception (const char *function)
 Construct exception, storing result of SDL_GetError()
 
 Exception (const Exception &)=default
 Copy constructor.
 
virtual ~Exception () noexcept
 Destructor.
 
std::string GetSDLFunction () const
 Get name of SDL function which caused an error.
 
std::string GetSDLError () const
 Get SDL2 error text.
 

Detailed Description

Exception object representing SDL2 error

Internally, libSDL2pp checks return value of each SDL2 function it calls which may fail. If the function fails, SDL2pp::Exception is thrown, and SDL2 error which explains cause of function failure is stored in the exception and may be extracted later.

what() usually contains a name of SDL2 function which failed, e.g. "SDL_Init() failed"

Note: this Exception object is used to report errors from SDL2 satellite libraries (SDL_image, SDL_mixer, SDL_ttf) as well. Though they use their own error handling functions (IMG_GetError, Mix_GetError, TTF_GetError), those are (currently) just macros pointing to SDL_GetError. We currently rely on that. If that changes, we'll need a hierarchy of specific exceptions.

Usage example:

{
try {
SDL2pp::SDL sdl(SDL_INIT_VIDEO);
} catch (SDL2pp::Exception& e) {
std::cerr << "Fatal error:"
<< e.what() // "SDL_Init failed"
<< ", SDL error: "
<< e.GetSDLError() // "x11 not available"
<< std::endl;
}
}
Exception object representing SDL2 error
Definition: Exception.hh:71
std::string GetSDLError() const
Get SDL2 error text.
Definition: Exception.cc:48
Helper class taking care of SDL library initialization and deinitialization.
Definition: SDL.hh:59

Constructor & Destructor Documentation

◆ Exception() [1/2]

SDL2pp::Exception::Exception ( const char *  function)
explicit

Construct exception, storing result of SDL_GetError()

Parameters
[in]functionName of SDL function which generated an error

◆ Exception() [2/2]

SDL2pp::Exception::Exception ( const Exception )
default

Copy constructor.

◆ ~Exception()

SDL2pp::Exception::~Exception ( )
virtualnoexcept

Destructor.

Member Function Documentation

◆ GetSDLError()

std::string SDL2pp::Exception::GetSDLError ( ) const

Get SDL2 error text.

Returns
Stored result of SDL_GetError()
See also
http://wiki.libsdl.org/SDL_GetError

◆ GetSDLFunction()

std::string SDL2pp::Exception::GetSDLFunction ( ) const

Get name of SDL function which caused an error.

Returns
Name of function which caused an error

The documentation for this class was generated from the following files: