I am using some php reference code to create an exception test, but getting some weird message.
here is the code:
function inverse($x) { if (!$x) { throw new Exception('Division by zero.'); } else return 1/$x; } try { echo inverse(5) . "\n"; echo inverse(0) . "\n"; } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; }
And here is the conclusion:
0.2 ( ! ) Exception: Division by zero. in /var/www/OOPlearing/slash.php on line 10Call Stack#TimeMemoryFunctionLocation10.0002330188{main}( )../slash.php:020.0002330232inverse( $x = 0 )../slash.php:17Dump $_SERVER$_SERVER['HTTP_HOST'] =string 'localhost' (length=9)$_SERVER['SERVER_NAME'] =string 'localhost' (length=9)Dump $_GETVariables in local scope (#2)$x =int 0 Caught exception: Division by zero.Hello World
It is strange that although the exception was caught, the exception message is still included ...
Some of my local settings in php.ini:
error_reporting = E_ALL & ~E_DEPRECATED display_errors =On display_startup_errors = Off log_errors = Off ...... html_errors = On
My notebook:
ubuntu11.04 mysql Ver 14.14 Distrib 5.1.54 PHP 5.3.5-1
Update (2012.1.16) . This is the xdebug extension that led to such error output. By default, xdebug shows stack traces under error conditions. For those who want to disable it, you can run the command:
xdebug_disable();
more details
source share