Would I want to throw an exception or an error in this PHP script?

Posted by Tower on Stack Overflow See other posts from Stack Overflow or by Tower
Published on 2009-07-01T14:58:15Z Indexed on 2010/05/09 20:38 UTC
Read the original article Hit count: 161

Filed under:
|

Hi,

I have a PHP script that runs database queries. Now, if a query fails, should I trigger an error or throw an exception? I noticed that if I do the latter, the script execution will stop after facing the exception.

My code is as follows:

if (!$this->connection[0]->query($this->query))
    throw new Exception($this->connection[0]->error);

What are the pros and cons of using exceptions for this kind of cases (failed queries)?

© Stack Overflow or respective owner

Related posts about php

Related posts about exception-handling