#include "CExceptionManager.hpp"

void HandleException(const CException& e, bool fatal) {

	std::string windowMessage(e.getMessage());
	windowMessage += "\nException reported in \"";
	windowMessage += DEFAULT_REPORT_PATH;
	windowMessage += "\".";

	CFileManager fm(DEFAULT_REPORT_PATH);

	try {
		fm.write(e.what());
	}
	catch (const std::exception& nothandled) {
		(void)nothandled;
	}

	if (!fatal) {
		// Just warning.
		SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING,
			"Error !",
			windowMessage.c_str(),
			NULL);
	} else {
		// Fatal error.
		SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
			"Fatal error !",
			windowMessage.c_str(),
			NULL);
		// It's fatal, so we quit.
		exit(EXIT_FAILURE);
	}
}