westminster86 Posted April 4, 2008 Share Posted April 4, 2008 Can someone explain to me why I am getting the following error. I dont see what ive done wrong. Parse error: parse error, unexpected '{' try { // line error if (!filled_out($_POST)) { throw new Exception('You have not filled the form out correctly. Please go back and try again.'); } } catch (Exception $e) { echo $e->getMessage(); exit; } Link to comment https://forums.phpfreaks.com/topic/99530-exception-handling/ Share on other sites More sharing options...
westminster86 Posted April 4, 2008 Author Share Posted April 4, 2008 For some reason im not getting the parse error on the WampServer. However, it doesnt seem to allow me to use the try block on the server im using. I may be wrong tho. Why does it work on the WampServer and not on the other one? Any Ideas? Link to comment https://forums.phpfreaks.com/topic/99530-exception-handling/#findComment-509220 Share on other sites More sharing options...
p2grace Posted April 4, 2008 Share Posted April 4, 2008 The try catch is for PHP5, what type of php are you using? Link to comment https://forums.phpfreaks.com/topic/99530-exception-handling/#findComment-509223 Share on other sites More sharing options...
westminster86 Posted April 4, 2008 Author Share Posted April 4, 2008 I was thinking that myself. I emailed the technical support and it is PHP5. So why doesnt it work? Link to comment https://forums.phpfreaks.com/topic/99530-exception-handling/#findComment-509230 Share on other sites More sharing options...
westminster86 Posted April 4, 2008 Author Share Posted April 4, 2008 Is there an alternative to the try block? Link to comment https://forums.phpfreaks.com/topic/99530-exception-handling/#findComment-509232 Share on other sites More sharing options...
p2grace Posted April 4, 2008 Share Posted April 4, 2008 You can check to see if a given var has been created. <?php if(!isset($_POST['var'])){ echo "error"; } ?> Link to comment https://forums.phpfreaks.com/topic/99530-exception-handling/#findComment-509233 Share on other sites More sharing options...
PFMaBiSmAd Posted April 4, 2008 Share Posted April 4, 2008 The fatal parse error is because you are missing a semi-colon ; on the end of the following line. Fatal parse errors mean your syntax is incorrect - catch (Exception $e) The error is not showing up on your WampServer because the display errors setting is off. When learning php, developing php code, or debugging php code, turn on display errors and full php error reporting in php.ini (when you have access to it), a .htaccess file (when php is running as an Apache module), or in a local php.ini (when php is running as a cgi wrapper) to get php to help you. Turning on display errors and full php error reporting in your script won't help with fatal parse errors because the code will never run to turn the settings on. Link to comment https://forums.phpfreaks.com/topic/99530-exception-handling/#findComment-509310 Share on other sites More sharing options...
p2grace Posted April 4, 2008 Share Posted April 4, 2008 No, you don't use a semicolon there, you use a {, which he has on the following line. Link to comment https://forums.phpfreaks.com/topic/99530-exception-handling/#findComment-509311 Share on other sites More sharing options...
PFMaBiSmAd Posted April 4, 2008 Share Posted April 4, 2008 Thanks, upon further review, the syntax in the posted code is correct (and executes on my development system.) Your parse error indicates the line number where php discovered something un-expected and could not figure out what to do. Posting the full error message and then several (10 - 15) lines of code up to and including the line with the error would help. Link to comment https://forums.phpfreaks.com/topic/99530-exception-handling/#findComment-509328 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.