On Monday, 25 August 2014 at 02:17:47 UTC, Mike Parker wrote:
// Put this somewhere you can import it into any module calling

Small modification for even terser error handling:

T sdlEnforce(T)(T result, string message = null)
{
  if (!result)
    throw new SdlException("SDL error: "
      ~ (message ? message ~ ": " : "")
      ~ to!string(SDL_GetError()));
  return result;
}

Usage:

gWindow = SDL_CreateWindow(...).sdlEnforce("SDL_CreateWindow");

class SDLError : Error {

This is misuse of the Error class. Don't do this, subclass Exception instead. D errors should be used to indicate logic errors (conditions that can only arise from a bug in the program), not failures in 3rd-party libraries.

Reply via email to