Checking of return values in constructors
This commit is contained in:
parent
b48f8cac73
commit
5c673e9abf
4 changed files with 12 additions and 3 deletions
|
@ -107,8 +107,9 @@ namespace font {
|
|||
manager::manager()
|
||||
{
|
||||
const int res = TTF_Init();
|
||||
if(res < 0) {
|
||||
if(res == -1) {
|
||||
std::cerr << "Could not initialize true type fonts\n";
|
||||
throw error();
|
||||
} else {
|
||||
std::cerr << "Initialized true type fonts\n";
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace font {
|
|||
struct manager {
|
||||
manager();
|
||||
~manager();
|
||||
struct error {};
|
||||
};
|
||||
|
||||
//function which sets the name of the font to use
|
||||
|
|
|
@ -830,6 +830,8 @@ int main(int argc, char** argv)
|
|||
return play_game(argc,argv);
|
||||
} catch(CVideo::error&) {
|
||||
std::cerr << "Could not initialize video. Exiting.\n";
|
||||
} catch(font::manager::error&) {
|
||||
std::cerr << "Could not initialize fonts. Exiting\n";
|
||||
} catch(config::error& e) {
|
||||
std::cerr << e.message << "\n";
|
||||
} catch(gui::button::error&) {
|
||||
|
|
|
@ -204,10 +204,15 @@ CVideo::CVideo( int x, int y, int bits_per_pixel, int flags)
|
|||
{
|
||||
const int res = SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE);
|
||||
if(res < 0) {
|
||||
throw error();
|
||||
std::cerr << "Could not initialize SDL: " << SDL_GetError() << "\n";
|
||||
throw CVideo::error();
|
||||
}
|
||||
|
||||
setMode( x, y, bits_per_pixel, flags );
|
||||
const int mode_res = setMode( x, y, bits_per_pixel, flags );
|
||||
if (mode_res == 0) {
|
||||
std::cerr << "Could not set Video Mode\n";
|
||||
throw CVideo::error();
|
||||
}
|
||||
}
|
||||
|
||||
CVideo::~CVideo()
|
||||
|
|
Loading…
Add table
Reference in a new issue