1

I am creating a webapp using codeigniter. I want to implement a error handling function. Say for example if I call a method of a model, and if an error occurs in that method, the error handler comes into action to return some pre-formatted string.

I was thinking of creating something like MY_Model, which every model class extends. Then, I can add the error handler in MY_Model class. But whether this can be done is beyond me right now. (yes I am a newbie at this)

Any enlightening ideas will help.

Regards

1 Answer 1

3

What I tend to do is return an array instead of a boolean. This array contains 2 keys, 'return' and 'error'.

In case of an error this array will look like the following:

array('return' => FALSE, 'error' => 'Some error')

In case of a successful execution this array will look like the following:

array('return' => TRUE)

The controller then verifies these results and if there's an error it will display the one set in the 'error' key.

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

3 Comments

@Yorick - That's how you have implemented the error handling. I want to know where to implement it?
Those arrays are returned by the model to the controller which then validates it.
Does that mean putting a try catch inside every method of model, so that when an exception is caught, the array is returned??

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.