3

I've been wondering what's the best way to deal with exceptions on CodeIgniter. The usual way is to use trigger_error() or log_message(), however I've been wondering if there's a better way using try/catch.

Any tips or recommendations on how to implement this into CodeIgniter?

Currently I'm extending the Exceptions Class, but I would like to know if someone else already dealt with this problem before.

1
  • 1
    What sort of exceptions are you trying to catch? Commented Nov 8, 2009 at 3:36

1 Answer 1

4

I would do something as simple as:

try { $this->load->model('modelname'); }

catch ( Exception $e )
{
    show_error($e);
}

If you application is environment aware then I would show_error() on local, email error on live. This functionality could even be added into MY_Model to work generically for all models.

Sign up to request clarification or add additional context in comments.

1 Comment

Not sure if this was correct in earlier versions of CI, but this doesn't work because load() will show_error() before the exception is caught.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.