1 #include "ge211_error.hxx"
11 namespace exceptions {
13 static const char* take_sdl_error()
15 const char* result = SDL_GetError();
22 return message_->c_str();
25 Exception_base::Exception_base(
const std::string& message)
26 : message_{std::make_shared<std::string>(message)}
29 Environment_error::Environment_error(
const std::string& message)
30 : Exception_base(message)
33 Client_logic_error::Client_logic_error(
const std::string& message)
39 oss <<
"\n\nERROR\n=====\n\n"
40 << action <<
" requires an active GE211 session. GE211 sessions\n"
41 <<
"are managed RAII-style by the ge211::Abstract_game class, so\n"
42 <<
"a session will be active whenever you have an instance of a\n"
43 <<
"class derived from Abstract_game, including within that derived\n"
44 <<
"game class's constructor and member functions.\n";
49 Session_needed_error::Session_needed_error(
const std::string& action)
54 static std::string build_late_paint_message(
char const* who) {
56 oss <<
"\n\nERROR\n=====\n\n"
58 <<
": Cannot paint to a ge211::internal::Render_sprite\n"
59 "that has already been rendered.\n";
64 Late_paint_error::Late_paint_error(
char const* who)
65 : Client_logic_error(build_late_paint_message(who))
69 const char* reason = take_sdl_error();
72 if (message.
empty()) {
75 oss <<
": " << reason;
80 oss <<
"\n (reason from SDL: " << reason <<
")";
88 : Environment_error{build_sdl_error_message(message)}
95 File_error File_error::could_not_open(
const std::string& filename)
97 return File_error(
"Could not open: " + filename);
101 : Host_error{message}
104 Font_error Font_error::could_not_load(
const std::string& filename)
106 return Font_error(
"Could not load font: " + filename);
109 Ge211_logic_error::Ge211_logic_error(
const std::string& message)
110 : Environment_error(
"Apparent ge211 bug! " + message)
113 Image_error::Image_error(
const std::string& message)
114 : Host_error{message}
117 Image_error Image_error::could_not_load(
const std::string& filename)
119 return Image_error(
"Could not load image: " + filename);
122 Mixer_error::Mixer_error(
const std::string& message)
123 : Host_error{message}
126 Mixer_error Mixer_error::could_not_load(
const std::string& filename)
128 return Mixer_error(
"Could not load music: " + filename);
131 Mixer_error Mixer_error::out_of_channels()
133 return Mixer_error(
"Could not play effect: out of channels");
136 Mixer_error Mixer_error::not_enabled()
138 return Mixer_error(
"Mixer is not enabled");
151 case Log_level::debug:
153 case Log_level::info:
155 case Log_level::warn:
168 return Log_message{std::move(reason), Log_level::debug};
173 return Log_message{std::move(reason), Log_level::info};
178 return Log_message{std::move(reason), Log_level::warn};
193 : reason_{std::move(reason)}
198 message_ <<
"ge211[" << log_level_string(level) <<
"]: ";
209 if (!reason_.
empty())
std::cerr <<
"\n (Reason: " << reason_ <<
")";
220 using namespace internal::logging;
224 return info(take_sdl_error());
227 Log_message warn_sdl()
229 return warn(take_sdl_error());
232 Log_message fatal_sdl()
234 return fatal(take_sdl_error());