Welcome Guest, Not a member yet? Register   Sign In
ActiveRecord Error Handling
#1

[eluser]ColonelChlorine[/eluser]
Hi all,
I'm having trouble using error handling with CI's ActiveRecord. Here is part of my controller's code. The $post variable contains the $this->input->post() object and $catID is the ID of my category. Finally the set_flash method is my own extension in MY_Session.php.

Code:
try {
    $this->db->update("Category", $post, "id=$catID");
    $this->session->set_flash("Successfully saved category", "success");
} catch (Exception $e) {
    $this->session->set_flash("Error saving category: ".$e->getMessage(), "error");
}

The problem is that my catch block never gets called because $this->db->update just causes a hard fail (via echoing an error and calling "exit();").

This seems to me like a terrible way to handle errors on CodeIgniter's part ... I should be in charge of how those errors get handled. For instance in this case I want to redirect back to the page and display a session flash message saying there was an error. Has anyone has similar experience with this problem?

Right now I have two paths for recourse:
1) Try to extend the DB_driver so that it properly throws exceptions rather than simply exiting
2) Just use a different ORM framework altogether

Am I missing something? How does everyone else handle these errors?

Cheers,
chlorine




Theme © iAndrew 2016 - Forum software by © MyBB