I'm having quiet weird problem with catching SwiftMailer's exceptions in Silex. I want to send an email like this:
try {
$message = \Swift_Message::newInstance()
->setSubject('subject')
->setFrom(array('form'))
->setTo(array('to'))
->setBody('body');
$app['mailer']->send($message);
} catch (\Swift_TransportException $e) {
$app['logger']->addError('Unable to send welcome email');
}
I know it's not going to send any email on localhost and I'm expecting it to fail but why I can't catch the Swift_TransportException
exception in try - catch
block?
It just prints:
Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host localhost [Connection refused #61]'