title: swiftmailer Swift_TransportException gets uncaught by try-catch block
body: <p>For a project (which is about estate properties) i have included a contact form where a visitor can contact an estate broker if the visitor is interested to buy/hire an estate property.</p>
  
  <p>I am using Symfony2 and its library. For the contact mail, i am using the Swiftmailer library.
  Well, i have the next code which handles the form submit. there, I create a mail object to be able to send mails. It works, but i want to provide a error resolving service if there are problems with the smtp host from sender/receiver.</p>
  
  <p>Here is the code,</p>
  
  <pre><code>$data = $contactForm-&gt;getData();
  try {
      // create body text
      $body = $app['twig']-&gt;render('mailTemplate.twig', array('data' =&gt; $data, 'immoid' =&gt; $immoID));
      // set mail
      $mail = \Swift_Message::newInstance()
          -&gt;setSubject('Contact reaction on your immo offer.')
          -&gt;setFrom($app['swiftconfig']['sender'])
          -&gt;setTo($contactinfo['contactmail'])
          -&gt;setBody($body, 'text/html');
      // send mail
      $app['mailer']-&gt;send($mail);
      // redirect if successfull
      $app-&gt;redirect($app['url_generator']-&gt;generate('immoDetail', array('immoID' =&gt; $immoID)));
  }
  catch (Swift_TransportException $STe) {
      // logging error
      $string = date("Y-m-d H:i:s")  . ' - ' . $STe-&gt;getMessage() . PHP_EOL;
      file_put_contents("errorlog.txt", $string, FILE_APPEND);
      // send error note to user
      $errorMsg = "the mail service has encountered a problem. Please retry later or contact the site admin.";
  }
  catch (Exception $e) {
      // logging error
      $string = date("Y-m-d H:i:s")  . ' - GENERAL ERROR - ' . $e-&gt;getMessage() . PHP_EOL;
      file_put_contents("errorlog.txt", $string, FILE_APPEND);
      // redirect to error page
      $app-&gt;abort(500, "Oops, something went seriously wrong. Please retry later !");
  }
  </code></pre>
  
  <p><em>($app['swiftconfig']['sender'] = mailaddress from host / $contactinfo['contactmail'] = mailaddress from site visitor (submitted in contact form))</em></p>
  
  <p>Now, when the smtp host doesn't work, Swiftmailer DOES send an exception, but the try-catch block ISN'T catching it. The function is just being continued. 
  Even the root try-catch block (in app.php) isn't catching it too. As a result of this, you see a large PHP error on the webpage, which shouldn't happen. The message from it is described here below, </p>
  
  <pre><code>SCREAM: Error suppression ignored for
  ---
  Fatal error: Uncaught exception 'Swift_TransportException' with message ' in C:\...\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php on line 266
  ---
  Swift_TransportException: Connection could not be established with host &lt;output omitted&gt;
  </code></pre>
  
  <p>Does anyone know why the try catch block isn't catching the custom exception ? I have investigated the class files and the progress, but i don't see any unusual activity. </p>
  
  <p>I hope that someone can come with a solution to this because PHP errors shouldn't appear on site pages.</p>