title: Can't catch SwiftMailer Exception?
body: <p>I'm using SwiftMailer (standalone).</p>
  
  <p>The code below works fine but when I enter an invalid SMTP credentials, an error like this is shown with an entire stack trace:</p>
  
  <pre><code>Failed to authenticate on SMTP server with username "MYUSERNAME" using 3 possible authenticators. Authenticator CRAM-MD5 returned Swift_TransportException: Expected response code 235 but got code "535", with message "535 5.7.0 Invalid login or password
  " in /var/www/tester/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:457
  Stack trace:
  #0 /var/www/tester/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(341): Swift_Transport_AbstractSmtpTransport-&gt;assertResponseCode('535 5.7.0 Inval...', Array)
  #1 /var/www/tester/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php(305): Swift_Transport_AbstractSmtpTransport-&gt;executeCommand('NmE0ODlmMWNmOTc...', Array, Array, false, NULL)
  #2 /var/www/tester/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/CramMd5Authenticator.php(39): Swift_Transport_EsmtpTransport-&gt;executeCommand('NmE0ODlmMWNmOTc...', Array)
  #3 /var/www/tester/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/Esmtp/AuthHandler.php(177): Swift_Transport_Esmtp_Auth_CramMd5Authenticator-&gt;authenticate(Object(Swift_SmtpTransport), 'MYUSERNAME', 'MYPASSWORD')
  #4 /var/www/tester/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php(371): Swift_Transport_Esmtp_AuthHandler-&gt;afterEhlo(Object(Swift_SmtpTransport))
  #5 /var/www/tester/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(148): Swift_Transport_EsmtpTransport-&gt;doHeloCommand()
  #6 /var/www/tester/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mailer.php(65): Swift_Transport_AbstractSmtpTransport-&gt;start()
  #7 /var/www/tester/public/index.php(32): Swift_Mailer-&gt;send(Object(Swift_Message))
  #8 {main}. Authenticator LOGIN returned Swift_TransportException: Expected response code 250 but got an empty response in /var/www/tester/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:445
  Stack trace:
  #0 /var/www/tester/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(341): Swift_Transport_AbstractSmtpTransport-&gt;assertResponseCode('', Array)
  #1 /var/www/tester/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php(305): Swift_Transport_AbstractSmtpTransport-&gt;executeCommand('RSET\r\n', Array, Array, false, NULL)
  #2 /var/www/tester/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/LoginAuthenticator.php(40): Swift_Transport_EsmtpTransport-&gt;executeCommand('RSET\r\n', Array)
  #3 /var/www/tester/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/Esmtp/AuthHandler.php(177): Swift_Transport_Esmtp_Auth_LoginAuthenticator-&gt;authenticate(Object(Swift_SmtpTransport), 'MYUSERNAME', 'MYPASSWORD')
  #4 /var/www/tester/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php(371): Swift_Transport_Esmtp_AuthHandler-&gt;afterEhlo(Object(Swift_SmtpTransport))
  #5 /var/www/tester/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(148): Swift_Transport_EsmtpTransport-&gt;doHeloCommand()
  #6 /var/www/tester/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mailer.php(65): Swift_Transport_AbstractSmtpTransport-&gt;start()
  #7 /var/www/tester/public/index.php(32): Swift_Mailer-&gt;send(Object(Swift_Message))
  #8 {main}. Authenticator PLAIN returned Swift_TransportException: Expected response code 250 but got an empty response in /var/www/tester/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:445
  Stack trace:
  #0 /var/www/tester/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(341): Swift_Transport_AbstractSmtpTransport-&gt;assertResponseCode('', Array)
  #1 /var/www/tester/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php(305): Swift_Transport_AbstractSmtpTransport-&gt;executeCommand('RSET\r\n', Array, Array, false, NULL)
  #2 /var/www/tester/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/PlainAuthenticator.php(39): Swift_Transport_EsmtpTransport-&gt;executeCommand('RSET\r\n', Array)
  #3 /var/www/tester/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/Esmtp/AuthHandler.php(177): Swift_Transport_Esmtp_Auth_PlainAuthenticator-&gt;authenticate(Object(Swift_SmtpTransport), 'MYUSERNAME', 'MYPASSWORD')
  #4 /var/www/tester/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php(371): Swift_Transport_Esmtp_AuthHandler-&gt;afterEhlo(Object(Swift_SmtpTransport))
  #5 /var/www/tester/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(148): Swift_Transport_EsmtpTransport-&gt;doHeloCommand()
  #6 /var/www/tester/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mailer.php(65): Swift_Transport_AbstractSmtpTransport-&gt;start()
  #7 /var/www/tester/public/index.php(32): Swift_Mailer-&gt;send(Object(Swift_Message))
  #8 {main}.done
  </code></pre>
  
  <p>Sample code:</p>
  
  <pre><code>&lt;?php
  
  try {
  
      $transport = (new Swift_SmtpTransport($host, $port))
          -&gt;setUsername($user)
          -&gt;setPassword($pass);
  
      $mailer = new \Swift_Mailer($transport);
  
      $message = (new \Swift_Message('test'))
          -&gt;setFrom(['foo@example.com' =&gt; 'bar'])
          -&gt;setTo(['foo@example.com'])
          -&gt;setBody('test');
  
      $mailer-&gt;send($message);
  
  } catch (\Swift_TransportException $ex) {
  
      echo $ex-&gt;getMessage();
  
  } catch (\Exception $ex) {
  
      echo $ex-&gt;getMessage();
  }
  </code></pre>
  
  <p>Isn't it suppose to catch Exceptions?</p>
  
  <p>Any ideas?</p>