diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-06-19 13:48:59 +0200 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-06-19 13:48:59 +0200 |
commit | c6c68cbc60711b43e8a570d708db3768240fcc5a (patch) | |
tree | 7a249d8981f54028ef03b2eadf9a908f4c5f65c6 | |
parent | 7d915dd6d61786d861ecf3f3415f08b85375a3a5 (diff) |
errors are no longer thrown as exceptions, but are php fatal errors, so that they more closely match the zend error reporting system
-rw-r--r-- | include/fatalerror.h | 66 | ||||
-rw-r--r-- | zend/fatalerror.cpp | 31 |
2 files changed, 97 insertions, 0 deletions
diff --git a/include/fatalerror.h b/include/fatalerror.h new file mode 100644 index 0000000..b178f25 --- /dev/null +++ b/include/fatalerror.h @@ -0,0 +1,66 @@ +/** + * FatalError.h + * + * + * Normally, fatal errors are reported with a call to zend_error(). + * + * However, this will trigger a longjmp(), which will cause objects + * constructed in the extension not to be destructed. We use therefore + * this FatalError class, which is a normally exception that _does_ + * cause objects to be destructed. + * + * When it is caught, right before control is handed back to the Zend + * engine, it will turn the exception into a zend_error() call and + * thus a longjmp. + * + * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> + * @copyright 2014 Copernica BV + */ + +/** + * Set up namespace + */ +namespace Php { + +/** + * Class definition + */ +class FatalError : public Exception +{ +public: + /** + * Constructor + * @param message + */ + FatalError(const std::string &message) : Exception(message) {} + + /** + * Destructor + */ + virtual ~FatalError() throw() + { + } + + /** + * Is this a native exception (one that was thrown from C++ code) + * @return bool + */ + virtual bool native() const + { + // although it is native, we return 0 because it should not persist + // as exception, but it should live on as zend_error() in stead + return false; + } + + /** + * Report this error as a fatal error + * @return bool + */ + virtual bool report() const override; +}; + +/** + * End of namespace + */ +} + diff --git a/zend/fatalerror.cpp b/zend/fatalerror.cpp new file mode 100644 index 0000000..e57be73 --- /dev/null +++ b/zend/fatalerror.cpp @@ -0,0 +1,31 @@ +/** + * FatalError.cpp + * + * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> + * @copyright 2014 Copernica BV + */ +#include "includes.h" + +/** + * Set up namespace + */ +namespace Php { + +/** + * Report this error as a fatal error + * @return bool + */ +bool FatalError::report() const +{ + // report the error + zend_error(E_ERROR, "%s", what()); + + // return true: it was reported + return true; +} + +/** + * End of namespace + */ +} + |