PkmnLib/CInterface/Core.hpp

30 lines
1.3 KiB
C++
Raw Normal View History

#ifndef PKMNLIB_CORE_HPP
#define PKMNLIB_CORE_HPP
#include <cstring>
#include <exception>
#include <string>
#define export extern "C"
// CreatureLibException is 1, so use 2.
#define PkmnLibException 2
class ExceptionHandler {
static std::string _lastException;
public:
static void SetLastException(const std::exception& e) { _lastException = std::string(e.what()); }
static const char* GetLastException() { return _lastException.c_str(); }
};
#define Try(data) \
try { \
data; \
return 0; \
} catch (const std::exception& e) { \
ExceptionHandler::SetLastException(e); \
2020-04-28 12:48:56 +00:00
return PkmnLibException; \
}
#endif // PKMNLIB_CORE_HPP