Page 1 of 1

Catching/handling exceptions Swift_BadResponseException

Posted: Tue Aug 28, 2007 2:31 pm
by EricWinchell
Can anyone tell me how to catch this exception and gracefully handle it? I'm trying to create a sort of spooler daemon and don't want the script to die.


Fatal error: Uncaught exception 'Swift_BadResponseException' with message 'Expec
ted response code(s) [250] but got response []' in C:\Program Files\Apache Group
\Apache2\htdocs\cap\trunk\app\vendors\Swift.php:250
Stack trace:
#0 C:\Program Files\Apache Group\Apache2\htdocs\cap\trunk\app\vendors\Swift.php(
310): Swift->assertCorrectResponse(Object(Swift_Events_ResponseEvent), 250)
#1 C:\Program Files\Apache Group\Apache2\htdocs\cap\trunk\app\vendors\Swift.php(
262): Swift->command('HELO localhost....', 250)
#2 C:\Program Files\Apache Group\Apache2\htdocs\cap\trunk\app\vendors\Swift.php(
220): Swift->handshake(Object(Swift_Events_ResponseEvent))
#3 C:\Program Files\Apache Group\Apache2\htdocs\cap\trunk\app\vendors\Swift.php(
101): Swift->connect()
#4 C:\Program Files\Apache Group\Apache2\htdocs\cap\trunk\app\email_spooler.php(
48): Swift->__construct(Object(Swift_Connection_SMTP))
#5 {main}
thrown in C:\Program Files\Apache Group\Apache2\htdocs\cap\trunk\app\vendors\S
wift.php on line 250

Posted: Tue Aug 28, 2007 2:37 pm
by EricWinchell
I suppose the exception just needs to be caught, like this?

Code: Select all

try {
        $swift->send( ... );
    } catch (Exception $e) {
        do_something_with_failed($recipient);
        $swift->reset();
    }

Posted: Tue Aug 28, 2007 3:26 pm
by Chris Corbyn
EricWinchell wrote:I suppose the exception just needs to be caught, like this?

Code: Select all

try {
        $swift->send( ... );
    } catch (Exception $e) {
        do_something_with_failed($recipient);
        $swift->reset();
    }
The exception isn't being thrown during the send(), it's being thrown during the "new Swift(...)" call. You need to use a try/catch yes ;)

Posted: Tue Aug 28, 2007 6:09 pm
by EricWinchell
I love lamp

Posted: Tue Aug 28, 2007 10:56 pm
by snursita
I also have the same problem, and unfortunately I use PHP4. How can I catch the exception? Sorry I never emulate a try catch in PHP4 before.

Posted: Wed Aug 29, 2007 3:37 am
by Chris Corbyn
snursita wrote:I also have the same problem, and unfortunately I use PHP4. How can I catch the exception? Sorry I never emulate a try catch in PHP4 before.
PHP4 is being dropped in February, because it's a pain to deal with, but basically you need to use set_error_handler() to catch the errors and deal with them. There is a Swift_Error::expect() workaround but I've not had a massive amount of success with it unless you know the implementation (i.e. it works for me, but does unexpected things for others).

If you can upgrade to PHP5, or push your host to upgrade then do that, otherwise jusy use set_error_handler().

http://www.swiftmailer.org/gophp5/