Jump to content

Exception handling


westminster86

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.