diff --git a/DyLib.hpp b/DyLib.hpp index 5e83186..2fb6c52 100644 --- a/DyLib.hpp +++ b/DyLib.hpp @@ -30,18 +30,28 @@ class DyLib void *m_handle{nullptr}; #endif public: - class handle_error : public std::runtime_error + class exception : public std::exception { + protected: + const std::string m_error; public: - handle_error(const char* message) : std::runtime_error(message) {}; - handle_error(const std::string &message) : std::runtime_error(message) {}; + exception(const char* message) : m_error(message) {} + exception(const std::string &message) : m_error(message) {}; + const char *what() const noexcept override {return m_error.c_str();}; }; - class symbol_error : public std::runtime_error + class handle_error : public exception { public: - symbol_error(const char* message) : std::runtime_error(message) {}; - symbol_error(const std::string &message) : std::runtime_error(message) {}; + handle_error(const char* message) : exception(message) {}; + handle_error(const std::string &message) : exception(message) {}; + }; + + class symbol_error : public exception + { + public: + symbol_error(const char* message) : exception(message) {}; + symbol_error(const std::string &message) : exception(message) {}; }; /** Creates a Dynamic Library object. @@ -107,7 +117,7 @@ class DyLib * @returns std::function that contains the function */ template - std::function getFunction(const char *name) + std::function getFunction(const char *name) const { #ifdef _WIN32 if (!m_handle) @@ -126,7 +136,7 @@ class DyLib } template - std::function getFunction(const std::string &name) + std::function getFunction(const std::string &name) const { return getFunction(name.c_str()); } @@ -140,7 +150,7 @@ class DyLib * @returns global variable of type */ template - Type getVariable(const char *name) + Type getVariable(const char *name) const { #ifdef _WIN32 if (!m_handle) @@ -159,7 +169,7 @@ class DyLib } template - Type getVariable(const std::string &name) + Type getVariable(const std::string &name) const { return getVariable(name.c_str()); } diff --git a/README.md b/README.md index b229ef3..a7b98ae 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ int main(int ac, char **av) if (ptr == nullptr) std::cout << "nullptr" << std::endl; } - catch (const std::runtime_error &e) { + catch (const DyLib::exception &e) { std::cerr << e.what() << std::endl; return EXIT_FAILURE; }