Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm developing web site on self made MVC engine. I have actionController that handles operations like register, login, post submit and etc. actionController receives operation name and parameters. Of course it mast handle errors such user with same nick already exists or password is to short about which action handler have to notify user. The question is which is the best way to organize errors, such that View could easily get localized user notification message.

I see two ways

First one: define error constants like


and localization map

local[ERR_NICK_BUSY] = 'User with the same nick already registered'
local[ERR_NICK_INVALID ] = 'Nick, you entered is invalid'

And second one: define abstract constants like


and pass them with field name. In this case localization looks like

local['nick_'+ERR_FIELD_BUSY] = 'User with the same nick already registered'

I don't like both this methods. Can you advise something else?

share|improve this question

How about extending the Exception class and throwing your own exceptions.

You could have a yml file with the error code, type, default message.

try {

/* some code */

} catch(MyException $e) {

    echo $e->getError(2)['message'];    


class MyException extends Exception{

function getError($code){

/* the parsed errors from the yml file */

    return $this->error[$code];



The yml file should be something like this

    type: 'Internal Error'
    message: 'An internal error occurred'
    code: 600

Cache the parsed yml if it gets to big

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.