Added error handling.

This commit is contained in:
Nicolás Ortega Froysa 2017-09-20 08:34:52 +02:00
parent f1657f1ffd
commit 47271ae5ff
No known key found for this signature in database
GPG Key ID: FEC70E3BAE2E69BF
3 changed files with 57 additions and 0 deletions

View File

@ -39,6 +39,7 @@ include_directories(
SYSTEM OPENDHT_INCLUDE_DIRS)
set(SRCS
src/error.cpp
src/node.cpp)
set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -Wextra -Wpedantic -Werror -Wfatal-errors -pedantic-errors -fno-elide-constructors")

33
src/error.cpp Normal file
View File

@ -0,0 +1,33 @@
/*
* Copyright (C) 2017 Ortega Froysa, Nicolás <nortega@themusicinnoise.net>
* Author: Ortega Froysa, Nicolás <nortega@themusicinnoise.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "neocomm.h"
#include "error.hpp"
#include <vector>
static std::vector<std::string> errors;
void add_error(std::string error) {
if(not errors.empty())
errors.push_back(error);
}
const char *NeoComm_get_last_error() {
return errors.back().c_str();
}

23
src/error.hpp Normal file
View File

@ -0,0 +1,23 @@
/*
* Copyright (C) 2017 Ortega Froysa, Nicolás <nortega@themusicinnoise.net>
* Author: Ortega Froysa, Nicolás <nortega@themusicinnoise.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <string>
void add_error(std::string error);