lixx: Uncaught exception 'Exception'

Beitrag lesen

Hallo Leute!

Ich studiere gerade die Möglichkeiten der Exception-Klasse, bekomme sie aber nicht zum laufen. Unter http://www.tutorialspoint.com/php/php_error_handling.htm gibt es ein Beispiel:

<?php  
//create function with an exception  
function checkNum($number)  
 {  
 if($number>1)  
  {  
  throw new Exception("Value must be 1 or below");  
  }  
 return true;  
 }  
  
//trigger exception in a "try" block  
try  
 {  
 checkNum(2);  
 //If the exception is thrown, this text will not be shown  
 echo 'If you see this, the number is 1 or below';  
 }  
  
//catch exception  
catch(Exception $e)  
 {  
 echo 'Message: ' .$e->getMessage();  
 }  
?>

Das sollte folgendes ausgeben:
"Message: Value must be 1 or below"

Bei mir kommt aber die Meldung:
"Fatal error: Uncaught exception 'Exception' with message 'Value must be 1 or below' in index.php:20 Stack trace: #0 index.php(28): checkNum(2) #1 {main} thrown in index.php on line 20"

Laut besagter Website geschieht das aber nur, wenn man die Exeption nicht catched. Was mache ich da falsch?

Folgendes Beispiel funzt aber:

<?php  
function exception_handler($exception) {  
  echo "Nicht aufgefangene Exception: " , $exception->getMessage(), "\n";  
}  
  
set_exception_handler('exception_handler');  
  
throw new Exception('Nicht aufgefangene Exception');  
echo "Nicht ausgeführt.\n";  
?>

Fehlt da noch ein set_exception_handler im obigen Beispiel?

lg lixx