# HG changeset patch # User Radek Brich # Date 1357684561 -3600 # Node ID 50308ed5e4f952769bd5541635fa73b54d529f9f # Parent 911927edbdde173780b649d0a1da1ef2d17ac6e1 sdlterm: Cleanup exceptions. diff -r 911927edbdde -r 50308ed5e4f9 sdlterm/src/sdlterm.cc --- a/sdlterm/src/sdlterm.cc Tue Jan 08 01:12:07 2013 +0100 +++ b/sdlterm/src/sdlterm.cc Tue Jan 08 23:36:01 2013 +0100 @@ -1,6 +1,5 @@ #include "sdlterm.h" -#include #include @@ -44,8 +43,7 @@ { if (TTF_Init() == -1) { - printf("TTF_Init: %s\n", TTF_GetError()); - throw std::exception(); + throw SDLTermError(std::string("TTF_Init: ") + TTF_GetError()); } } @@ -66,23 +64,21 @@ _font_regular = TTF_OpenFont(fname_regular, ptsize); if (!_font_regular) { - printf("TTF_OpenFont: %s\n", TTF_GetError()); - throw std::exception(); + throw SDLTermError(std::string("TTF_OpenFont: ") + TTF_GetError()); } // open bold font _font_bold = TTF_OpenFont(fname_bold, ptsize); if (!_font_bold) { - printf("TTF_OpenFont: %s\n", TTF_GetError()); - throw std::exception(); + throw SDLTermError(std::string("TTF_OpenFont: ") + TTF_GetError()); } // update metrics for regular font int advance; if (TTF_GlyphMetrics(_font_regular, 'M', NULL, NULL, NULL, NULL, &advance) == -1) { - printf("TTF_GlyphMetrics: %s\n", TTF_GetError()); + throw SDLTermError(std::string("TTF_GlyphMetrics: ") + TTF_GetError()); } _cell_width = advance; _cell_height = TTF_FontHeight(_font_regular); @@ -90,7 +86,7 @@ // read metrics for bold font if (TTF_GlyphMetrics(_font_bold, 'M', NULL, NULL, NULL, NULL, &advance) == -1) { - printf("TTF_GlyphMetrics: %s\n", TTF_GetError()); + throw SDLTermError(std::string("TTF_GlyphMetrics: ") + TTF_GetError()); } if (advance > _cell_width) { @@ -221,8 +217,7 @@ if (_screen_surface == NULL) { - fprintf(stderr, "Unable to set video: %s\n", SDL_GetError()); - throw std::exception(); + throw SDLTermError(std::string("SDL_SetVideoMode: ") + SDL_GetError()); } _pixel_width = pxwidth; @@ -312,8 +307,7 @@ { if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) { - fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError()); - throw std::exception(); + throw SDLTermError(std::string("SDL_Init: ") + SDL_GetError()); } SDL_EnableUNICODE(1); SDL_EnableKeyRepeat(250, SDL_DEFAULT_REPEAT_INTERVAL); @@ -436,8 +430,7 @@ break; // continue loop } } - fprintf(stderr, "SDL_WaitEvent error: %s\n", SDL_GetError()); - throw std::exception(); + throw SDLTermError(std::string("SDL_WaitEvent: ") + SDL_GetError()); } diff -r 911927edbdde -r 50308ed5e4f9 sdlterm/src/sdlterm.h --- a/sdlterm/src/sdlterm.h Tue Jan 08 01:12:07 2013 +0100 +++ b/sdlterm/src/sdlterm.h Tue Jan 08 23:36:01 2013 +0100 @@ -2,7 +2,9 @@ #include "SDL_ttf.h" #include +#include #include +#include namespace Style @@ -223,3 +225,17 @@ static Uint32 _wait_event_callback(Uint32 interval, void *param); }; + +class SDLTermError: public std::exception +{ +public: + SDLTermError(const std::string &a_msg) + : std::exception(), _msg(a_msg) {}; + virtual ~SDLTermError() throw() {}; + + virtual const char *what() const throw() { return _msg.c_str(); }; + +private: + std::string _msg; +}; +