From fbc43a400beb138f2ba6a26a2cc74c20a5cdf893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o=20Delabre?= Date: Thu, 24 Mar 2016 20:11:25 +0100 Subject: [PATCH] Prise en charge propre des exceptions --- src/main.cpp | 13 +++++++++++-- src/resource_manager.cpp | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1c0f6b1..f3dc232 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,6 +2,7 @@ #include "block.hpp" #include "engine.hpp" #include "constants.hpp" +#include #include int main() { @@ -62,6 +63,14 @@ int main() { engine.addObject(block21); engine.addObject(block22); - engine.start(); - return 0; + try { + engine.start(); + } catch (const std::exception& exception) { + std::cerr << std::endl; + std::cerr << "Le programme a quitté après une erreur d'exécution." << std::endl; + std::cerr << exception.what() << std::endl; + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; } diff --git a/src/resource_manager.cpp b/src/resource_manager.cpp index a418aea..31da7ec 100644 --- a/src/resource_manager.cpp +++ b/src/resource_manager.cpp @@ -41,7 +41,7 @@ sf::Texture& ResourceManager::getTexture(std::string name) { // tente de charger la texture dans le chemin "CWD/res/name" if (!texture.loadFromFile(path)) { - throw std::runtime_error("Impossible de charger l'image: " + name); + throw std::runtime_error("Impossible de charger l'image : " + name); } textures[name] = texture;