summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-03-06 17:58:39 +0100
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-03-06 17:58:39 +0100
commitfecab9b936f5985da254ca42976eeaf8dbcbea1d (patch)
treea1d2bd5fc59c646f89af9ce9de624a3386afe71d
parent2bd3471192b1ebd8f3841368db4b0eaa5643bf55 (diff)
changes to documentation, removed empty exception.cpp implementation, fixed exception handling
-rw-r--r--documentation/exceptions.html19
-rw-r--r--src/exception.cpp18
-rw-r--r--src/origexception.cpp6
-rw-r--r--src/value.cpp6
4 files changed, 19 insertions, 30 deletions
diff --git a/documentation/exceptions.html b/documentation/exceptions.html
index 1af4913..88af60f 100644
--- a/documentation/exceptions.html
+++ b/documentation/exceptions.html
@@ -126,15 +126,22 @@ extern "C" {
&lt;?php
// call "callMe" for the first time, and supply a function that returns "first call"
-echo(callMe(function() {
- return "first call\n";
-}));
+$output = callMe(function() {
+ return "First call";
+});
+
+// show output (this will be "First call")
+echo("$output\n");
// call "callMe" for the second time, but throw an exception this time
-echo(callMe(function() {
+$output = callMe(function() {
throw new Exception("Sorry...\n");
- return "second call\n";
-}));
+ return "Second call\n";
+});
+
+// show output (this will be "Exception caught")
+echo("$output\n");
+
?&gt;
</code></pre>
</p>
diff --git a/src/exception.cpp b/src/exception.cpp
deleted file mode 100644
index fe62c5b..0000000
--- a/src/exception.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-/**
- * 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/origexception.cpp b/src/origexception.cpp
index 4406158..e24131a 100644
--- a/src/origexception.cpp
+++ b/src/origexception.cpp
@@ -23,7 +23,7 @@ OrigException::OrigException(struct _zval_struct *zval) :
_restored(false)
{
// save the exception
- zend_exception_save();
+ //zend_exception_save();
}
/**
@@ -52,7 +52,7 @@ OrigException::~OrigException() noexcept
// skip if the exception was restored
if (_restored) return;
- // clean up the exception
+ // clean up the exception, because it was handled in C++ code
zend_clear_exception();
}
@@ -63,7 +63,7 @@ OrigException::~OrigException() noexcept
void OrigException::restore()
{
// restore the exception
- zend_exception_restore();
+ //zend_exception_restore();
// mark exception as restored
_restored = true;
diff --git a/src/value.cpp b/src/value.cpp
index 0cf1653..53d8c0a 100644
--- a/src/value.cpp
+++ b/src/value.cpp
@@ -1154,12 +1154,12 @@ Value Value::exec(int argc, zval ***params) const
// the current exception
zval *oldException = EG(exception);
-
+
// call the function
if (call_user_function_ex(CG(function_table), NULL, _val, &retval, argc, params, 1, NULL) != SUCCESS) return nullptr;
- // was an exception thrown?
- if (oldException != EG(exception)) throw OrigException(EG(exception));
+ // was an exception thrown? we throw a C++ new exception to give the C++ the chance to catch it
+ if (oldException != EG(exception) && EG(exception)) throw OrigException(EG(exception));
// no (additional) exception was thrown
return retval ? Value(retval) : nullptr;