Page 1 of 1

Problem with catching exceptions

Posted: Fri Feb 27, 2009 2:13 am
by Martin.h
I have the following code for catching a connection exception:

Code: Select all

 
$smtp =& new Swift_Connection_SMTP("mail.henridoorten.nl");
$smtp->setUsername("info@henridoorten.nl");
$smtp->setpassword("password");
    
try{
    $swift =& new Swift($smtp);
}catch (Swift_ConnectionException $e) {
    echo "There was a problem communicating with SMTP: " . $e->getMessage();
} 
 
But I still get the following error:
Fatal error:
Uncaught Error of type [Swift_ConnectionException] with message [Authentication failed using username 'info@henridoorten.nl' and password '********']
@0 include() in /usr/home/deb11522/domains/meubelproducten.nl/public_html/admin/show_order.php on line 4
@1 Swift::Swift() in /usr/home/deb11522/domains/meubelproducten.nl/public_html/admin/include/storingEmail.php on line 14
@2 Swift::connect() in /usr/home/deb11522/domains/meubelproducten.nl/public_html/admin/include/classes/Swiftmailer/Swift.php on line 109
@3 Swift::handshake() in /usr/home/deb11522/domains/meubelproducten.nl/public_html/admin/include/classes/Swiftmailer/Swift.php on line 230

in /usr/home/deb11522/domains/meubelproducten.nl/public_html/admin/include/classes/Swiftmailer/Swift/Errors.php on line 99
Why do I not catch the exception? What am I doing wrong?

Re: Problem with catching exceptions

Posted: Fri Feb 27, 2009 2:19 am
by John Cartwright
I believe it should be

Code: Select all

try{
    $smtp =& new Swift_Connection_SMTP("mail.henridoorten.nl");
    $smtp->setUsername("info@henridoorten.nl");
    $smtp->setpassword("password");
 
    $swift =& new Swift($smtp);
}catch (Swift_ConnectionException $e) {
    echo "There was a problem communicating with SMTP: " . $e->getMessage();
}
Edit | Actually I'm not so sure, considering the exception stacktrace shows it originates ffrom the Swift object

Re: Problem with catching exceptions

Posted: Fri Feb 27, 2009 2:23 am
by Martin.h
I also tried that, but I get the same result.

Re: Problem with catching exceptions

Posted: Fri Feb 27, 2009 3:11 am
by Chris Corbyn
Use the PHP5 version. They're not real Exceptions in the PHP4 version since PHP4 did not have Exceptions. They're a nuisance to work with so just get the PHP5 version instead.

Re: Problem with catching exceptions

Posted: Fri Feb 27, 2009 3:33 am
by Martin.h
That was it! Thanks!