From:             Lutz dot Zetzsche at sea-rescue dot de
Operating system: 
PHP version:      Irrelevant
PHP Bug Type:     Documentation problem
Bug description:  Addition of lacking basic information to the Exceptions 
documentation page

Description:
------------
The introductory page about exceptions in PHP5 is lacking some basic
information with some good, ready-to-use examples:

1. Throwing an exception and catching an exception are two separate
things. The exception can be caught everywhere in the code.

2. The exception is passed through the call stack, until the exception is
caught or a fatal error occurs.

This information is part of an user contributed note from 06-May-2005
07:15, but is vital enough to appear in the documentation itself.

Reproduce code:
---------------
http://www.php.net/manual/en/language.exceptions.php
http://www.php.net/manual/en/language.exceptions.php#52612

Expected result:
----------------
<?php
function a($x) {
  echo 'Calling function a($x), $x='.$x."\n";
  if ($x < 0) {
    $error = 'Error: $x < 0';
    throw new Exception($error);
  }
}

function b($y) {
  echo 'Calling function b($x), $y='.$y."\n";
  a($y);
}

try {
  b(-10);
  echo('OK! No exception caught.'."\n\n");
} catch (Exception $e) {
  echo 'Caught exception: ',  $e->getMessage(), "\n\n";
}

try {
  b(10);
  echo('OK! No exception caught.'."\n\n");
} catch (Exception $e) {
  echo 'Caught exception: ',  $e->getMessage(), "\n\n";
}

// Continue execution
echo 'Hello World';
?>

Actual result:
--------------
<?php
try {
   $error = 'Always throw this error';
   throw new Exception($error);

   // Code following an exception is not executed.
   echo 'Never executed';

} catch (Exception $e) {
   echo 'Caught exception: ',  $e->getMessage(), "\n";
}

// Continue execution
echo 'Hello World';
?>

-- 
Edit bug report at http://bugs.php.net/?id=39258&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=39258&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=39258&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=39258&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=39258&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=39258&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=39258&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=39258&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=39258&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=39258&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=39258&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=39258&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=39258&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=39258&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=39258&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=39258&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=39258&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=39258&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=39258&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=39258&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=39258&r=mysqlcfg

Reply via email to