[英]PHP - Uncaught SoapFault exception - how to ignore it and continue while loop?
我試圖忽略錯誤並繼續執行腳本,但是我做不到。 這是我的代碼:
try
{
$client = new SoapClient('http://allegro.pl/uploader.php?wsdl');
$version = $client->doQueryAllSysStatus(1, $allegro_user_webapi_key);
$version = get_object_vars($version[0]);
$session = $client->doLoginEnc($allegro_username, base64_encode(hash('sha256', $allegro_user_pass, true)), 1, $allegro_user_webapi_key, $version['ver-key']);
$i = 0;
$tab = array();
while( (time() - $time) >= 240 )
{
$i++;
$get = $client->doShowUser($allegro_user_webapi_key, 1, 15, ''); // HERE IS A PROBLEM
$tab[] = $get['userLogin'];
}
echo $i.'<br><br>'."\n\n";
var_dump($tab);
}
catch(TemplateException $e)
{
// continue
}
當我在此處添加“ @”時:
$get = @$client->doShowUser($allegro_user_webapi_key, 1, 15, '');
它不起作用...當我刪除try and catch時,它也無法正常工作。 如何確定可以忽略這些錯誤並繼續執行腳本?
謝謝。
在嘗試捕獲中,您正在捕獲類型為TemplateException
異常。
這不會捕獲所引發的異常,因為它是一個SoapFaultException
try {
...
} catch (TemplateException $e) {
// do something when a TemplateException is thrown
} catch (SoapFaultException $e) {
// do something when a SoapFaultException is thrown
} catch (Exception $e) {
// catch any other exception that is thrown
}
嘗試捕獲按順序處理( TemplateException
> SoapFaultException
> ..)
如果只想捕獲SoapFaultException
,則可以執行以下操作:
try {
...
} catch (SoapFaultException $e) {
// do something when a SoapFaultException is thrown
}
如果要捕獲所有異常,無論類型如何:
try {
...
} catch (Exception $e) {
// catch all exceptions that are thrown
}
如果您只想捕獲由doShowUser
觸發的doShowUser
並且仍然繼續while
循環,那么您將需要移動try catch
while( (time() - $time) >= 240 )
{
try {
$i++;
// HERE IS A PROBLEM
$get = $client->doShowUser($allegro_user_webapi_key, 1, 15, '');
$tab[] = $get['userLogin'];
} catch (Exception $e) {
// do nothing
}
}
將嘗試捕獲放入循環
while( (time() - $time) <= 240 )
{
$i++;
try{
$get = $client->doShowUser($allegro_user_webapi_key, 1, 15, ''); // HERE IS A PROBLEM
}
catch(Exception $e)
{
// do smthing
}
$tab[] = $get['userLogin'];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.