#include <Pluma/DLibrary.hpp>\r
#include <cstdio>\r
#include <string>\r
+#include <stdexcept>\r
\r
\r
namespace pluma{\r
////////////////////////////////////////////////////////////\r
DLibrary* DLibrary::load(const std::string& path){\r
if ( path.empty() ){\r
- fprintf(stderr, "Failed to load library: Empty path\n");\r
+ // fprintf(stderr, "Failed to load library: Empty path\n");\r
+ throw std::runtime_error( "Failed to load library: Empty path." );\r
return NULL;\r
}\r
void* handle = NULL;\r
#ifdef PLUMA_SYS_WINDOWS\r
handle = ::LoadLibraryA(path.c_str());\r
if (!handle){\r
- fprintf(stderr, "Failed to load library \"%s\".\n", path.c_str());\r
- return NULL;\r
+ //fprintf(stderr, "Failed to load library \"%s\".\n", path.c_str());\r
+ throw std::runtime_error(\r
+ std::string( "Failed to load library \"" ) +\r
+ path +\r
+ std::string( "\"." );\r
+ );\r
+ return NULL;\r
}\r
#else\r
handle = ::dlopen(path.c_str(), RTLD_NOW);\r
if (!handle){\r
const char* errorString = ::dlerror();\r
- fprintf(stderr, "Failed to load library \"%s\".", path.c_str());\r
- if(errorString) fprintf(stderr, " OS returned error: \"%s\".", errorString);\r
- fprintf(stderr, "\n");\r
+ std::string error_text = "Failed to load library \"";\r
+ // fprintf(stderr, "Failed to load library \"%s\".", path.c_str());\r
+ if(errorString) error_text += std::string( errorString ); // fprintf(stderr, " OS returned error: \"%s\".", errorString);\r
+ // fprintf(stderr, "\n");\r
+ throw std::runtime_error( error_text + std::string( "\"." ) );\r
return NULL;\r
}\r
#endif\r
////////////////////////////////////////////////////////////\r
void* DLibrary::getSymbol(const std::string& symbol){\r
if (!handle){\r
- fprintf(stderr, "Cannot inspect library symbols, library isn't loaded.\n");\r
+ //fprintf(stderr, "Cannot inspect library symbols, library isn't loaded.\n");\r
+ throw std::runtime_error( "Cannot inspect library symbols, library isn't loaded." );\r
return NULL;\r
}\r
void* res;\r
res = (void*)(::dlsym(handle, symbol.c_str()));\r
#endif\r
if (!res){\r
- fprintf(stderr, "Library symbol \"%s\" not found.\n", symbol.c_str());\r
- return NULL;\r
+ // fprintf(stderr, "Library symbol \"%s\" not found.\n", symbol.c_str());\r
+ throw std::runtime_error(\r
+ std::string( "Library symbol \"" ) +\r
+ symbol +\r
+ std::string( "\" not found." )\r
+ );\r
+ return NULL;\r
}\r
return res;\r
}\r