vendredi 3 août 2018

Laravel try catch not working, cant catch exception from a package

I am using a package https://github.com/barbushin/php-imap to read email from mail server, I have the following code

$folder = Storage::disk('local')->getAdapter()->getPathPrefix();
try {
    $mailbox = new \PhpImap\Mailbox('{imap.gmail.com:993/imap/ssl}INBOX', 'xxxxx@gmail.com', 'xxxxxxxxxx', $folder);    
}
catch(\Exception $e) {
    return 'rroor';
}

but is not catching error, I want to log the error if login fails.

The following code is throwing the exception

if(!$result) {
    $errors = imap_errors();
    if($errors) {
        if($throwExceptionClass) {
            throw new $throwExceptionClass("IMAP method imap_$methodShortName() failed with error: " . implode('. ', $errors));
        }
        else {
            return false;
        }
    }
}

How can I catch this exception on my controller method ?

see the error page

enter image description here



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire