summaryrefslogtreecommitdiff
path: root/fuzzylite/src/Exception.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fuzzylite/src/Exception.cpp')
-rw-r--r--fuzzylite/src/Exception.cpp89
1 files changed, 45 insertions, 44 deletions
diff --git a/fuzzylite/src/Exception.cpp b/fuzzylite/src/Exception.cpp
index d24adac..1c27e70 100644
--- a/fuzzylite/src/Exception.cpp
+++ b/fuzzylite/src/Exception.cpp
@@ -1,48 +1,47 @@
/*
- Author: Juan Rada-Vilela, Ph.D.
- Copyright (C) 2010-2014 FuzzyLite Limited
- All rights reserved
+ fuzzylite (R), a fuzzy logic control library in C++.
+ Copyright (C) 2010-2017 FuzzyLite Limited. All rights reserved.
+ Author: Juan Rada-Vilela, Ph.D. <jcrada@fuzzylite.com>
This file is part of fuzzylite.
fuzzylite is free software: you can redistribute it and/or modify it under
- the terms of the GNU Lesser General Public License as published by the Free
- Software Foundation, either version 3 of the License, or (at your option)
- any later version.
+ the terms of the FuzzyLite License included with the software.
- fuzzylite 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 Lesser General Public License
- for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with fuzzylite. If not, see <http://www.gnu.org/licenses/>.
-
- fuzzyliteâ„¢ is a trademark of FuzzyLite Limited.
+ You should have received a copy of the FuzzyLite License along with
+ fuzzylite. If not, see <http://www.fuzzylite.com/license/>.
+ fuzzylite is a registered trademark of FuzzyLite Limited.
*/
#include "fl/Exception.h"
-#ifdef FL_BACKTRACE_OFF
-//do nothing
+#ifdef FL_BACKTRACE
-#elif defined FL_UNIX
+#ifdef FL_UNIX
#include <execinfo.h>
#elif defined FL_WINDOWS
#include <windows.h>
#include <winbase.h>
+
#ifndef __MINGW32__
+/*Disable warning 8.1\Include\um\dbghelp.h(1544):
+warning C4091: 'typedef ': ignored on left of '' when no variable is declared*/
+#pragma warning (push)
+#pragma warning (disable:4091)
#include <dbghelp.h>
+#pragma warning (pop)
#endif
+
+#endif
+
#endif
-#include <signal.h>
-#include <stdlib.h>
-#include <string.h>
+#include <csignal>
+#include <cstring>
namespace fl {
@@ -58,8 +57,7 @@ namespace fl {
FL_DBG(this->what());
}
- Exception::~Exception() FL_INOEXCEPT {
- }
+ Exception::~Exception() FL_INOEXCEPT { }
void Exception::setWhat(const std::string& what) {
this->_what = what;
@@ -90,23 +88,25 @@ namespace fl {
}
std::string Exception::btCallStack() {
-#ifdef FL_BACKTRACE_OFF
- return "[backtrace disabled] fuzzylite was built with option -DFL_BACKTRACE_OFF";
+#ifndef FL_BACKTRACE
+ return "[backtrace disabled] fuzzylite was built without -DFL_BACKTRACE";
#elif defined FL_UNIX
std::ostringstream btStream;
const int bufferSize = 30;
void* buffer[bufferSize];
- int backtraceSize = backtrace(buffer, bufferSize);
- char **btSymbols = backtrace_symbols(buffer, backtraceSize);
+ int backtraceSize = ::backtrace(buffer, bufferSize);
+ char **btSymbols = ::backtrace_symbols(buffer, backtraceSize);
if (btSymbols == fl::null) {
btStream << "[backtrace error] no symbols could be retrieved";
} else {
- if (backtraceSize == 0) btStream << "[backtrace is empty]";
+ if (backtraceSize == 0) {
+ btStream << "[backtrace is empty]";
+ }
for (int i = 0; i < backtraceSize; ++i) {
btStream << btSymbols[i] << "\n";
}
}
- free(btSymbols);
+ ::free(btSymbols);
return btStream.str();
@@ -123,51 +123,52 @@ namespace fl {
} else {
btSymbol->MaxNameLen = 255;
btSymbol->SizeOfStruct = sizeof ( SYMBOL_INFO);
- if (backtraceSize == 0) btStream << "[backtrace is empty]";
+ if (backtraceSize == 0) {
+ btStream << "[backtrace is empty]";
+ }
for (int i = 0; i < backtraceSize; ++i) {
SymFromAddr(GetCurrentProcess(), (DWORD64) (buffer[ i ]), 0, btSymbol);
btStream << (backtraceSize - i - 1) << ": " <<
btSymbol->Name << " at 0x" << btSymbol->Address << "\n";
}
}
- free(btSymbol);
+ ::free(btSymbol);
return btStream.str();
#else
return "[backtrace missing] supported only in Unix and Windows platforms";
#endif
}
- //execinfo
- void Exception::signalHandler(int signal) {
+ void Exception::signalHandler(int unixSignal) {
std::ostringstream ex;
- ex << "[unexpected signal " << signal << "] ";
+ ex << "[unexpected signal " << unixSignal << "] ";
#ifdef FL_UNIX
- ex << strsignal(signal);
+ ex << ::strsignal(unixSignal);
#endif
ex << "\nBACKTRACE:\n" << btCallStack();
- fl::Exception::catchException(fl::Exception(ex.str(), FL_AT));
- exit(EXIT_FAILURE);
+ Exception::catchException(Exception(ex.str(), FL_AT));
+ ::exit(EXIT_FAILURE);
}
- void Exception::convertToException(int signal) {
+ void Exception::convertToException(int unixSignal) {
std::string signalDescription;
#ifdef FL_UNIX
//Unblock the signal
sigset_t empty;
sigemptyset(&empty);
- sigaddset(&empty, signal);
+ sigaddset(&empty, unixSignal);
sigprocmask(SIG_UNBLOCK, &empty, fl::null);
- signalDescription = strsignal(signal);
+ signalDescription = ::strsignal(unixSignal);
#endif
std::ostringstream ex;
- ex << "[signal " << signal << "] " << signalDescription << "\n";
+ ex << "[signal " << unixSignal << "] " << signalDescription << "\n";
ex << "BACKTRACE:\n" << btCallStack();
- throw fl::Exception(ex.str(), FL_AT);
+ throw Exception(ex.str(), FL_AT);
}
void Exception::terminate() {
- fl::Exception::catchException(fl::Exception("[unexpected exception] BACKTRACE:\n" + btCallStack(), FL_AT));
- exit(EXIT_FAILURE);
+ Exception::catchException(Exception("[unexpected exception] BACKTRACE:\n" + btCallStack(), FL_AT));
+ ::exit(EXIT_FAILURE);
}
void Exception::catchException(const std::exception& exception) {