Catch swiftmailer exception in Symfony2 dev env controller

Viewed 4844

Im not sure why Im not catching exceptions from Swiftmailer in my controller. What am I doing wrong, or missing?

In a controller I have:

try {
    $this->get('mailer')->send($email);
}
catch (\Swift_TransportException $e) {
    $result = array(
        false, 
        'There was a problem sending email: ' . $e->getMessage()
    );
}

It seems to get caught by Symfony before it gets to my code, so instead of being able to handle the error myself I get the standard 500 page with Swift_TransportException: Connection could not be established

If the email can't be sent there is no need for the application to halt as the email isn't critical - I just want to issue a notice.

Maybe there's a way to disable Symfonys catching of certain exceptions or for certain Controllers?

2 Answers
Related