This is a pretty simple question, and it's blatantly my own newb status that's holding me back. Apologies.
Why isn't this bit of code working?
try
{
create_account($accountXML);
echo "<p>Successfully created your account.</p>";
try
{
create_page($pageXML,$base64_credentials);
echo "<p>Successfully created your page!</p>";
}
catch (exception $e){ echo "<p>$e</p>"; }
}
catch(exception $e)
{
echo "<p>$e</p>";
}
catch(emailInUseException $e)
{
echo "<p>Error: Email already in use. Could not create account.</p>";
}
Within the create_account
function...
if ((!substr_count($response, "200 Account created successfully") > 0)) // If failed
{
if ((substr_count($response, "400 EmailAddressInUse") > 0)) // If email address already in use
{
throw new emailInUseException($response);
}
throw new exception("Error: Could not create account. Reason: $response");
}
The emailInUse
catch doesn't seem to be working :(
Update: With debugging enabled I get the following error: Fatal error: Class 'emailInUseException' not found
I'm sure it's something really awfully obvious. Thanks for any help.
catch(emailInUse $e)
{
echo "<p>Error: Email already in use. Could not create account.</p>";
}
catch(exception $e)
{
echo "<p>$e</p>";
}
You need to change the order. The more general exceptions need to come to the bottom, otherwise your code will simply catch it and throw it before the specific exception is caught.