Skip to content

Commit d3fe4f3

Browse files
author
Manuel Guenther
committed
Added a bob::core::NotImplementedError and relates it to the python NotImplementedError.
1 parent 789caf8 commit d3fe4f3

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

cxx/core/core/Exception.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,21 @@ namespace bob {
8989
mutable std::string m_message;
9090
};
9191

92+
93+
/**
94+
* A NotImplementedError is raised when a specific function of a class
95+
* is only implementable in certain subclasses, but not in the current one.
96+
*/
97+
class NotImplementedError: public Exception {
98+
99+
public:
100+
NotImplementedError(const std::string& reason = "This function cannot be implemented in this class") throw();
101+
virtual ~NotImplementedError() throw();
102+
virtual const char* what() const throw();
103+
104+
private:
105+
std::string m_reason;
106+
};
92107
}
93108

94109
}

cxx/core/src/Exception.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,14 @@ const char* bob::core::DeprecationError::what() const throw() {
5858
}
5959
}
6060

61+
bob::core::NotImplementedError::NotImplementedError(const std::string& reason) throw()
62+
: m_reason(reason)
63+
{}
64+
65+
bob::core::NotImplementedError::~NotImplementedError() throw() {
66+
}
67+
68+
const char* bob::core::NotImplementedError::what() const throw() {
69+
return m_reason.c_str();
70+
}
71+

python/core/src/exception.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ void bind_core_exception() {
5454
register_exception_translator<std::underflow_error>(PyExc_ArithmeticError);
5555

5656
register_exception_translator<bob::core::Exception>(PyExc_RuntimeError);
57+
register_exception_translator<bob::core::NotImplementedError>(PyExc_NotImplementedError);
5758

5859
// note: only register exceptions to which you need specific behavior not
5960
// covered by catching RuntimeError

0 commit comments

Comments
 (0)