From df717775f6e484cd8901e01d5a355f1683fbeb64 Mon Sep 17 00:00:00 2001 From: JasperVanEck Date: Fri, 29 Nov 2013 10:53:22 +0100 Subject: Partial Exception implementation added, inherits from std::exception --- include/exception.h | 28 ++++++++++++++++------------ phpcpp.h | 1 + src/exception.cpp | 1 + src/function.cpp | 4 ++-- src/libphpcpp.so | Bin 132635 -> 132689 bytes 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/include/exception.h b/include/exception.h index ea328fe..f787582 100644 --- a/include/exception.h +++ b/include/exception.h @@ -5,6 +5,7 @@ * @author Jasper van Eck * @copyright 2013 Copernica BV */ +#include /** * Set up namespace @@ -14,41 +15,44 @@ namespace Php { /** * Class definition */ -class Exception +class Exception : public std::exception { private: /** * The exception message - * @var char* + * @var char* */ - char* _message; + std::string _message; public: /** * Constructor - * @param string The exception message. + * @param &string */ - Exception(char* message) throw() + Exception(const std::string &message) : std::exception(), _message(message) { - _message = message; } - + /** - * Destructor + * Destructor */ - ~Exception() throw() + virtual ~Exception() { } /** * Returns the message of the exception. - * @return std::string + * @return &string */ - char* getMessage() const throw() + std::string &message() throw() { return _message; } - }; +/** + * End of namespace + */ } + + diff --git a/phpcpp.h b/phpcpp.h index 170613f..37ccb4b 100644 --- a/phpcpp.h +++ b/phpcpp.h @@ -17,6 +17,7 @@ #include #include #include +#include /** * Include all headers files that are related to this library diff --git a/src/exception.cpp b/src/exception.cpp index 19591db..f60f27c 100644 --- a/src/exception.cpp +++ b/src/exception.cpp @@ -14,4 +14,5 @@ namespace Php { + } diff --git a/src/function.cpp b/src/function.cpp index fe96745..ef9cf78 100644 --- a/src/function.cpp +++ b/src/function.cpp @@ -43,9 +43,9 @@ void invoke_function(INTERNAL_FUNCTION_PARAMETERS) // get the result result = function->invoke(*PHPCPP_G(environment), params); } - catch (const Php::Exception &exception) + catch (Php::Exception &exception) { - zend_throw_exception(zend_exception_get_default(), exception.getMessage(), 0 TSRMLS_CC); + zend_throw_exception(zend_exception_get_default(), (char*)exception.message().c_str(), 0 TSRMLS_CC); } } diff --git a/src/libphpcpp.so b/src/libphpcpp.so index d217cab..2b81ba7 100755 Binary files a/src/libphpcpp.so and b/src/libphpcpp.so differ -- cgit v1.2.3