Exceptions in database model, how do I handle it?
<p>I am creating a model for a small PHP application. This will utilize PDO to communicate with a MySQL-server. I have understood that the recommended error mode is the one which throws exceptions, as this allows for graceful error handling. But I don't understand how I should handle these exceptions?</p>

<p>Technically, it is easy, but let me give you an example:</p>

<pre><code>class Model()
{
    private $host = "localhost", 
            $user = "",
            $pass = "",
            $DBH;


    function __construct()
    {
        try
        { 
            $DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);

            $DBH-&gt;setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
        }  
        catch(PDOException $e)
        {  
            error_log($e-&gt;getMessage());
        }
    }
}
</code></pre>

<p>If I create an object Model in my controller, and it fails, I have no way of handling this in my controller, right? Or what happens when I create that object, "new Model" returns false? </p>

<p>Excuse me for being a newbie, but I want to be able to handle any exceptions also from other functions in the model. How should I go about this? I need to be able to know if something went wrong in my controller and be able to do the appropriate thing there.</p>
