There is no "should" or "best" way to do error handling.
Generally speaking, there are two types of errors
- Those which are handled by other parts of the program. The user never sees or knows about these errors, at least not in a direct manner.
- Those which have caused enough failure that the user needs to be informed as such.
Notice that neither of these have anything to do with the specific PHP mechanisms you'd use to handle errors.
If you use exceptions...
Then I recommend using exceptions across the board. Register an exception handler and let it do most of the work - including other PHP errors. Invalid login details?
class InvalidLoginException extends Exception
{
protected $message = 'Login information is incorrect. Please try again.';
}
Then you have a bunch of choices for implementation.
try {
$user->login(); // will throw and InvalidLoginException if invalid
}
catch ( InvalidLoginException $e )
{
// display an error message
}
Or, if you so choose, let the exception handler do it. Maybe even in a more flexible way
class ApplicationErrorException extends Exception{}
class InvalidLoginException extends ApplicationErrorException
{
protected $message = 'Login information is incorrect. Please try again.';
}
Then, in the exception handler
if ( $exception instanceof ApplicationErrorException )
{
// dislpay error message
}
But exceptions aren't the only way, and by some not even considered a good way.