summaryrefslogtreecommitdiff
path: root/include/fatalerror.h
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-06-19 13:48:59 +0200
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-06-19 13:48:59 +0200
commitc6c68cbc60711b43e8a570d708db3768240fcc5a (patch)
tree7a249d8981f54028ef03b2eadf9a908f4c5f65c6 /include/fatalerror.h
parent7d915dd6d61786d861ecf3f3415f08b85375a3a5 (diff)
errors are no longer thrown as exceptions, but are php fatal errors, so that they more closely match the zend error reporting system
Diffstat (limited to 'include/fatalerror.h')
-rw-r--r--include/fatalerror.h66
1 files changed, 66 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
+ */
+}
+