C++ bindings/wrapper for SDL2
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() More...
 Exception (const Exception &)=default
 Copy constructor. More...
virtual ~Exception () noexcept
 Destructor. More...
std::string GetSDLFunction () const
 Get name of SDL function which caused an error. More...
std::string GetSDLError () const
 Get SDL2 error text. More...

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 {
} 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.
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)

Construct exception, storing result of SDL_GetError()

[in]functionName of SDL function which generated an error

◆ Exception() [2/2]

SDL2pp::Exception::Exception ( const Exception )

Copy constructor.

◆ ~Exception()

SDL2pp::Exception::~Exception ( )


Member Function Documentation

◆ GetSDLError()

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

Get SDL2 error text.

Stored result of SDL_GetError()
See also

◆ GetSDLFunction()

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

Get name of SDL function which caused an error.

Name of function which caused an error

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