我正在使用ImapMail库并尝试启动一个新的邮箱:
try{
$mailbox = new ImapMailbox($url, $username, $password);
}catch (\Exception $e){
return new Response("fail");
}但是上面的尝试/捕捉不起作用,尽管symfony给了我以下内容:
Connection error: (is empty)
500 Internal Server Error - Exception 斯塔克斯迹
in vendor/php-imap/php-imap/src/PhpImap/Mailbox.php at line 67:
protected function initImapStream() {
$imapStream = @imap_open($this->imapPath, $this->imapLogin, $this->imapPassword, $this->imapOptions, $this->imapRetriesNum, $this->imapParams);
if(!$imapStream) {
throw new Exception('Connection error: ' . imap_last_error());
}
return $imapStream;
}它会抛出一个新的异常,为什么我不能抓住它呢?
任何暗示都很感激!
发布于 2015-10-29 12:18:06
原因很简单。只调用try块中的类构造函数。如果您查看类源代码,您将看到构造函数不调用任何东西。
https://github.com/barbushin/php-imap/blob/master/src/PhpImap/Mailbox.php#L20-L31
这意味着抛出异常的代码必须在“尝试/捕获”下面。如果要捕获异常,则必须将其移动到try块中。我说的是$mailbox->checkMailbox()。此命令引发异常。
https://stackoverflow.com/questions/33412004
复制相似问题