我将变得更清楚,我需要能够避免这个错误,而不是阻止错误所在的预测,并继续其他错误。在发送邮件时有避免错误的方法吗?我有一个完整的功能,当一封电子邮件出错时就停止,我只想让它继续工作,不管出错。
class MailBienvenida extends Notification
{
use Queueable;
protected $nombre;
protected $codigo;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($nombre, $codigo)
{
$this->nombre = $nombre;
$this->codigo = $codigo;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->line('Bienvenido ' . $this->nombre)
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}发布于 2022-02-03 23:57:16
如果您使用php7及以上。您可以像抛出异常一样抛出错误。所有可恢复的错误都是可捕捉的。此外,错误和异常都实现了一个名为Throwable的通用接口。
这意味着,当发生可抛出的错误时,您可以将调用包围在一个尝试捕获块中,然后简单地继续循环:
foreach ($array as $row) {
try {
$row->executeThatFunction();
} catch (Throwable $t) {
// you may want to add some logging here...
continue;
}
}https://stackoverflow.com/questions/70979603
复制相似问题