Skip to content

Commit

Permalink
Add the SDL exception class.
Browse files Browse the repository at this point in the history
  • Loading branch information
mordante committed Mar 23, 2014
1 parent e96bd0f commit f6b52f3
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Expand Up @@ -358,6 +358,7 @@ endif()

set(wesnoth-sdl_SRC
sdl/alpha.cpp
sdl/exception.cpp
sdl/texture.cpp
sdl/window.cpp
)
Expand Down
1 change: 1 addition & 0 deletions src/SConscript
Expand Up @@ -150,6 +150,7 @@ libcampaignd = env.Library("campaignd", libcampaignd_sources, OBJPREFIX = "campa
libwesnoth_sdl_sources = Split("""
sdl_utils.cpp
sdl/alpha.cpp
sdl/exception.cpp
sdl/texture.cpp
sdl/window.cpp
tracer.cpp
Expand Down
37 changes: 37 additions & 0 deletions src/sdl/exception.cpp
@@ -0,0 +1,37 @@
/*
Copyright (C) 2014 by Mark de Wever <koraq@xs4all.nl>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/

#include "sdl/exception.hpp"

#include <SDL_error.h>

namespace sdl
{

static std::string create_error(const std::string& operation,
const bool use_sdl_error)
{
if(use_sdl_error) {
return operation + " Error »" + SDL_GetError() + "«.\n";
} else {
return operation;
}
}

texception::texception(const std::string& operation, const bool use_sdl_error)
: game::error(create_error(operation, use_sdl_error))
{
}

} // namespace sdl
44 changes: 44 additions & 0 deletions src/sdl/exception.hpp
@@ -0,0 +1,44 @@
/*
Copyright (C) 2014 by Mark de Wever <koraq@xs4all.nl>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/

#ifndef SDL_EXCEPTION_HPP_INCLUDED
#define SDL_EXCEPTION_HPP_INCLUDED

/**
* @file
* Contains a basic exception class for SDL operations.
*/

#include "exceptions.hpp"

namespace sdl
{

struct texception : public game::error
{
/**
* Constructor.
*
* @param operation The operation that has failed.
* @param use_sdl_error If set to @c true the @p operation is
* appended with the SDL error message. Else the
* @p operation is the error message for the
* exception.
*/
texception(const std::string& operation, const bool use_sdl_error);
};

} // namespace sdl

#endif

0 comments on commit f6b52f3

Please sign in to comment.