Handling Errors In PHP When Using MVC

Posted by James Jeffery on Programmers See other posts from Programmers or by James Jeffery
Published on 2012-02-04T20:38:00Z Indexed on 2012/09/04 15:53 UTC
Read the original article Hit count: 352

Filed under:
|
|

I've been using Codeigniter a lot recently, but one thing that gets on my nerves is handling errors and displaying them to the user. I've never been good at handling errors without it getting messy. My main concern is when returning errors to the user.

Is it good practice to use exceptions and throw/catch exceptions rather than returning 0 or 1 from functions and then using if/else to handle the errors. Thus, making it easier to inform the user about the issue.

I tend to go away from exceptions. My Java tutor at university some years ago told me "exceptions shouldn't be used in production code it's more for debugging". I get the feeling he was lying.

But, an example, I have code that adds a user to a database. During the process more than 1 thing could go wrong, such as a database issue, a duplicate entry, a server issue, etc. When an issue happens during registration the user needs to know about it.

What's the best way to handle errors in PHP, keeping in mind that I'm using an MVC framework.

© Programmers or respective owner

Related posts about php

Related posts about mvc