Problem with catching exceptions

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
Martin.h
Forum Newbie
Posts: 5
Joined: Fri Jul 11, 2008 12:55 pm

Problem with catching exceptions

Post 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?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Problem with catching exceptions

Post 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
Martin.h
Forum Newbie
Posts: 5
Joined: Fri Jul 11, 2008 12:55 pm

Re: Problem with catching exceptions

Post by Martin.h »

I also tried that, but I get the same result.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Problem with catching exceptions

Post 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.
Martin.h
Forum Newbie
Posts: 5
Joined: Fri Jul 11, 2008 12:55 pm

Re: Problem with catching exceptions

Post by Martin.h »

That was it! Thanks!
Post Reply