Exceptions problem on PHP 5 ... HELP!

admin

Administrator
Staff member
Is there anything special I have to turn on in the .ini to get Exceptions supported? Believe it or not, the following is generating a parse error:

<?php
try {
throw new Exception( 'Uncaught exception' )
}
catch( Exception e ) {
// some error handling
}
?>

I'm using PHP 5.0.4 on both Darwin and Linux -- with same problem. Can any PHP5 guru out there shed some light on what I may be possibly doing wrong? Thanks!this works...

<?php

try {
throw new Exception('foo');
}
catch (Exception $e) {
echo $e->getmessage();
}

?>Believe it or not, the following is generating a parse error:
I believe it. As thorpe shows in his revised code... you're missing a semicolon at the end of your throw... line, and a dollar sign in front of the Exception variable.Sorry guys -- got so frustrated with this error, I simply typed it out and introduced the two real errors above. The corrected snippet from thorpe is generating the exact same parse error when I do a php -l from the command line:

Parse error: parse error in test.php on line 3
Errors parsing test.php

This is *so* basic, I can't imagine there's a problem with the source, seems more like an issue with my php environment. The code '$a = new Exception('Uncaught');' works just fine, the problem arises when I put the try/catch block in. Any idea what it may be, or how best to isolate the source of the problem? Thanks guys.hehe... i had this exact same parse error yesturday when i ran my example from the command line. running it via a browser in apache worked fine though. reason. do a php -v on the command line. if your setup is what i think it is, you cli version of php may be 4.x.x while the php_mod used by apache is 5.x.x.

maybe you have the same issue.You da maan, thorpe! That did it. Thanks much!
 
Back
Top