diff options
author | JasperVanEck <jaspergkurtz@gmail.com> | 2013-11-28 16:50:12 +0100 |
---|---|---|
committer | JasperVanEck <jaspergkurtz@gmail.com> | 2013-11-28 16:50:12 +0100 |
commit | b6665b72996d23522d8a277cf4acc3d46e5e11fa (patch) | |
tree | 816b5225806f60a043e35faa366f5becf9ca2f9f | |
parent | 9185842b1d2fd352f6d71a46d2017fa25cc3c6a7 (diff) |
Added a very basic exception class, and added an exception example
-rw-r--r-- | Examples/Exceptions/exception.php | 5 | ||||
-rw-r--r-- | include/exception.h | 54 | ||||
-rw-r--r-- | phpcpp.h | 1 | ||||
-rw-r--r-- | src/exception.cpp | 17 | ||||
-rw-r--r-- | src/function.cpp | 19 | ||||
-rw-r--r-- | src/includes.h | 4 | ||||
-rwxr-xr-x | src/libphpcpp.so | bin | 132258 -> 132736 bytes |
7 files changed, 85 insertions, 15 deletions
diff --git a/Examples/Exceptions/exception.php b/Examples/Exceptions/exception.php index 3f567b3..b288e23 100644 --- a/Examples/Exceptions/exception.php +++ b/Examples/Exceptions/exception.php @@ -15,11 +15,12 @@ try { - echo "Function which throws an exception; my_throw_exception_function()\n" + echo "Function which throws an exception; my_throw_exception_function()\n"; echo my_throw_exception_function() . "\n"; } catch (Exception $exception) { - + echo $exception->getMessage(); } + echo my_throw_exception_function() . "\n"; diff --git a/include/exception.h b/include/exception.h new file mode 100644 index 0000000..ea328fe --- /dev/null +++ b/include/exception.h @@ -0,0 +1,54 @@ +/** + * Exception.h + * Implementation of Php Exceptions. + * + * @author Jasper van Eck <jasper.vaneck@copernica.com> + * @copyright 2013 Copernica BV + */ + +/** + * Set up namespace + */ +namespace Php { + +/** + * Class definition + */ +class Exception +{ +private: + /** + * The exception message + * @var char* + */ + char* _message; + +public: + /** + * Constructor + * @param string The exception message. + */ + Exception(char* message) throw() + { + _message = message; + } + + /** + * Destructor + */ + ~Exception() throw() + { + } + + /** + * Returns the message of the exception. + * @return std::string + */ + char* getMessage() const throw() + { + return _message; + } + +}; + +} @@ -42,6 +42,7 @@ #include <phpcpp/class.h> #include <phpcpp/classinfo.h> #include <phpcpp/extension.h> +#include <phpcpp/exception.h> /** * Macro to export a function diff --git a/src/exception.cpp b/src/exception.cpp new file mode 100644 index 0000000..19591db --- /dev/null +++ b/src/exception.cpp @@ -0,0 +1,17 @@ +/** + * Exception.cpp + * Implementation of Php Exceptions. + * + * @author Jasper van Eck <jasper.vaneck@copernica.com> + * @copyright 2013 Copernica BV + */ + +#include "includes.h" + +/** + * Set up namespace + */ +namespace Php { + + +} diff --git a/src/function.cpp b/src/function.cpp index 9376751..fe96745 100644 --- a/src/function.cpp +++ b/src/function.cpp @@ -38,20 +38,15 @@ void invoke_function(INTERNAL_FUNCTION_PARAMETERS) Parameters params(this_ptr, ZEND_NUM_ARGS()); // the function could throw an exception - //try - //{ + try + { // get the result result = function->invoke(*PHPCPP_G(environment), params); - //} - //catch (const Php::Exception &exception) - //{ - // cout << "got exception"; - - // @todo throw the exception.... - - - - //} + } + catch (const Php::Exception &exception) + { + zend_throw_exception(zend_exception_get_default(), exception.getMessage(), 0 TSRMLS_CC); + } } /** diff --git a/src/includes.h b/src/includes.h index 87b5d64..ac99950 100644 --- a/src/includes.h +++ b/src/includes.h @@ -17,6 +17,7 @@ #include <map> #include <memory> #include <set> +#include <exception> // for debugging #include <iostream> @@ -25,7 +26,7 @@ * PHP includes */ #include <php.h> - +#include "zend_exceptions.h" /** * Macro to convert results to success status */ @@ -55,6 +56,7 @@ #include "../include/class.h" #include "../include/classinfo.h" #include "../include/extension.h" +#include "../include/exception.h" #include "../include/globals.h" /** diff --git a/src/libphpcpp.so b/src/libphpcpp.so Binary files differindex 2c5827d..8403d89 100755 --- a/src/libphpcpp.so +++ b/src/libphpcpp.so |