try{…}catch does not throw exception in PHP/Symfony2/PHPImap

I am using the ImapMail Library and try to initiate a new Mailbox:

    try{
        $mailbox = new ImapMailbox($url, $username, $password);
    }catch (\Exception $e){
        return new Response("fail");
    }

But the above try/catch does not work, although symfony gives me this:

Connection error: (is empty) 
 500 Internal Server Error - Exception 

the Stacktrace

 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;
    }

(Direct link to function on github)

It does throw a new Exception, why can’t I catch it?

Any hint appreciated!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s