Skip to content

Commit

Permalink
Added exceptions for unregistered python function and module use
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Sullivan committed Apr 17, 2016
1 parent ce21625 commit 9d2c162
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/pylingual.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
#include <Python.h>
#include <converters.hpp>
#include <error_handle.hpp>
#include <pylingual_exception.hpp>

using namespace std;

//class pylingual_exception;
class pylingual {

public:
Expand All @@ -29,6 +31,8 @@ class pylingual {
void function(const char* pyname, Args&&... args) {
if (functions.count(pyname)>0) {
functions[pyname](std::forward<Args>(args)...);
} else {
throw pylingual_unregistered();
}
}

Expand Down Expand Up @@ -95,5 +99,8 @@ pylingual::pylingual() {
modules["__builtin__"]=built_in;
}




#endif

12 changes: 12 additions & 0 deletions include/pylingual_exception.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <exception>
class pylingual_exception : public std::exception
{
public:
virtual const char* what() const noexcept { return "standard pylingual exception"; };
};

class pylingual_unregistered : public pylingual_exception
{
public:
virtual const char* what() const noexcept { return "Module/Function has not been imported"; };
};

0 comments on commit 9d2c162

Please sign in to comment.