From 2bd3471192b1ebd8f3841368db4b0eaa5643bf55 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Thu, 6 Mar 2014 17:12:28 +0100 Subject: changes to documentation --- documentation/exceptions.html | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'documentation') diff --git a/documentation/exceptions.html b/documentation/exceptions.html index 5d136d9..1af4913 100644 --- a/documentation/exceptions.html +++ b/documentation/exceptions.html @@ -67,14 +67,16 @@ exception caught

The example shows how amazingly simple it is to throw exceptions from your - C++ code, and catch them in your PHP script. Just as if you're not even - working in two different languages at the same time, you can simply throw - a Php::Exception object, and catch it in the PHP script. + C++ code, and to catch them in your PHP script. The PHP-CPP library will + internally catch your C++ exception and convert it into a PHP exception, + but this all happens under the hood. For you, the extension programmer, it + is as if you're not even working in two different languages, and you can + simply throw a Php::Exception object as if it was a regular PHP exception.

Catching exceptions in C++

But it works the other way around too. If your extensions calls a PHP - function, and the function happens to throw an exception, you can catch it + function, and that PHP function happens to throw an exception, you can catch it just as if it was a normal C++ exception.

@@ -90,7 +92,7 @@ Php::Value callMe(Php::Parameters ¶ms) } catch (Php::Exception &exception) { - return "Exception caught!"; + return "Exception caught!\n"; } } @@ -113,10 +115,11 @@ extern "C" {

The callMe() function from this example extension receives one single - parameter: a callback function that it will immediately call, and whose - return value is returned. If this callback function (which was supplied by - the user) throws an exception, it is detected by the callMe() function, and - it will return an alternative string ("Exception caught!") in stead. + parameter: a callback function that it will immediately call, and from which + the return value is also returned by the callMe() function. If this callback + that is passed to the callMe() somehow throws an exception, it will be caught + by the callMe() function, and the callMe() function will return an alternative + string instead ("Exception caught!").


@@ -124,14 +127,15 @@ extern "C" {
 
 // call "callMe" for the first time, and supply a function that returns "first call"
 echo(callMe(function() {
-    return "first call";
+    return "first call\n";
 }));
 
 // call "callMe" for the second time, but throw an exception this time
 echo(callMe(function() {
-    throw new Exception("Sorry...");
-    return "second call";
+    throw new Exception("Sorry...\n");
+    return "second call\n";
 }));
+?>
 

-- cgit v1.2.3