这是一个非常简单的问题,它公然是我自己的newb状态,阻止我回来。道歉。Try-Catch没有捕捉到自定义的异常类型
为什么这段代码不工作?
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>";
}
内create_account
功能...
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");
}
的emailInUse
捕捉似乎并不奏效:(
更新:调试启用我收到以下错误: Fatal error: Class 'emailInUseException' not found
我确定这真的很明显。谢谢你任何帮助。
'emailInUse'函数是什么? – Neal 2011-04-05 17:20:39
@Neal:'emailInUse'似乎是一个自定义的异常类型。可能更好地命名为'EmailInUseException',但我是谁来判断? – AgentConundrum 2011-04-05 17:25:08
@代理我会那样做的! – 2011-04-05 17:27:54