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?


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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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