Arbutils/CInterface/Core.hpp

36 lines
1.8 KiB
C++
Raw Normal View History

#ifndef ARBUTILS_CORE_HPP
#define ARBUTILS_CORE_HPP
#include <cstring>
#include <exception>
#include <string>
2020-08-15 12:52:15 +00:00
#include "../src/Exception.hpp"
2020-08-20 10:54:37 +00:00
#define export extern "C" [[maybe_unused]]
#define ArbutilsException 3;
class ExceptionHandler {
static std::string _ArbutilsLastException;
public:
2020-08-15 12:52:15 +00:00
static void SetLastException(const ArbUt::Exception& e) {
_ArbutilsLastException = std::string(e.what()) + "\n" + e.GetStacktrace();
}
static void SetLastException(const std::exception& e) { _ArbutilsLastException = std::string(e.what()); }
static const char* GetLastException() { return _ArbutilsLastException.c_str(); }
};
#define Try(data) \
try { \
data; \
return 0; \
2020-08-15 12:52:15 +00:00
} catch (const ArbUt::Exception& e) { \
ExceptionHandler::SetLastException(e); \
return ArbutilsException; \
} catch (const std::exception& e) { \
ExceptionHandler::SetLastException(e); \
return ArbutilsException; \
}
#endif // ARBUTILS_CORE_HPP