]> granicus.if.org Git - php/commitdiff
Update Exceptions example.
authorSebastian Bergmann <sebastian@php.net>
Sat, 29 Dec 2001 08:17:57 +0000 (08:17 +0000)
committerSebastian Bergmann <sebastian@php.net>
Sat, 29 Dec 2001 08:17:57 +0000 (08:17 +0000)
Zend/ZEND_CHANGES

index 57b02ea6777d1dad0729398df26af222ade6c477..5f399ba4eca9708027e54cad4c1d696bd7a85b90 100644 (file)
@@ -47,22 +47,37 @@ Changes in the Zend Engine 2.0
 
         Example
 
-        try {
-          code
+          <?php
+          class MyException {
+            function MyException($_error) {
+              $this->error = $_error;  
+            }
+
+            function getException() {
+              return $this->error;     
+            }
+          }
 
-          if (failure) {
-            throw new MyException(Failure);
+          function ThrowException() {
+            throw new MyException("'This is an exception!'");  
           }
 
-          code
-        } catch ($exception) {
-          handle exception
+          try {
+          } catch ($exception) {
+            print "There was an exception: " . $exception->getException();
+            print "\n";
+          }
 
-          throw $exception; // Re-throw exception.
-        }
+          try {
+            ThrowException();  
+          } catch ($exception) {
+            print "There was an exception: " . $exception->getException();
+            print "\n";
+          }
+          ?>
 
-      Old code that does not use exceptions will run without
-      modifications.
+      Old code that does not define user-space functions 'catch', 
+      'throw' and 'try' will run without modifications.
 
     * Namespaces.