PHP web application when to use try/catch

Viewed 33530

I am using PHP with CodeIgniter framework. I read some articles that stating using try/catch methods is in bad practice.

I understand to use logging in development when a potential error can occur and let the actual error happen then log it using log_message('level', 'message')

But when in deployment you want to suppress and handle any errors that arise. Should I be using try/catch blocks, for instance in something like...

try { 
    $this->data['important'] = $this->Test_Model->do_something($data);
    if(empty(data['important'])) {
    throw new Exception('no data returned');
}

catch (Exception $e) {
    //alert the user then kill the process
    var_dump($e->getMessage());
}

I'm confused when I use be using try/catch correctly.

2 Answers
Related