I'm wondering if you see anything terribly wrong with this code, or if you see any areas for improvement. My objective is to make sure its simple enough for someone else taking over my job to be able to pick up fairly quickly.
My basic question has to do with the fact that in my model, I'm trying to distinguish between system errors that I want to show the end user, and ones that I don't want them to see. Here's some code from my model:
public function macaddresses($ip, $name)
{
try
{
//some code....
if ( $obj->connect() )
{
//do something else
return $macaddies
}
else
{
throw new Exception('Connection');
} //end if
}
catch (Exception $e)
{
$this->error_handler($e->getMessage());
return false;
}//end catch
}//end function
private function error_handler($emess)
{
switch ($emess)
{
case 'Connection':
$userfriendlyemess = "Unable to connect to device. Please contact administrator!";
break;
//handling unknown errors
default:
$userfriendlyemess = "Oops! Something big just happened.";
log_message('error', $emess); //write to ci logs
break;
}// end switch
throw new Exception($userfriendlyemess);
} // end function
Finally, the logic in my controller is where I make the calls to show_error. I know in CI i can use templates or something... but since I don't think there are going to be too many cases in my switch statement, i thought i'd try this approach. any suggestions would be appreciated.