Welcome Guest, Not a member yet? Register   Sign In
Error Handling Coding Styles: What's your Preference?
#2

[eluser]xwero[/eluser]
I think option 1 is a bit over-abstracted, certainly if it is a stand alone library. You would have to check each time you change something if you don't have overlapping numbers and you have to keep track of them.

I go with option 2 with a few changes
- add an public/not public flag for the errors so it can be dealt with in the controller (redirects too)
- put the error strings in a language file
- on success return an empty string instead of a boolean
To add it all up in code you would have something like this in your controller
Code:
$check = register($password, $username);
if(empty($check))
{
   // success
}
else
{
  $temp = explode('|',$check);
  if($temp[0] == 0) // public error
  {
    // show error + optional redirection
  }
  else
  {
    // show generic error + developers choice + optional redirection
  }
}

If you go with option 3 i think the database failure/file error will be skipped often because it should work, even CI has this 'sin'. I guess it's up to the developer to decide which errors should be cached for display.


Messages In This Thread
Error Handling Coding Styles: What's your Preference? - by El Forum - 01-04-2008, 01:50 AM
Error Handling Coding Styles: What's your Preference? - by El Forum - 01-04-2008, 02:36 AM



Theme © iAndrew 2016 - Forum software by © MyBB