From: Tomasz K. <ev...@in...> - 2007-07-04 23:39:26
|
Hi again, In ZNF currently there is very simple error handling system. It will be changed in near future, but my improvement has the same problem as currently used. I'd like to focus on one disadvantage of it: When you want to add new error you do it in this way: $errors->addError(1, $translation->get('noNewsFound')); There is one big problem here: using integers. If you have seen ZNF_Action_ActionErrors you can notice, that these integers are key in array, where errors are kept. So at the beginning I wanted to find out some good idea: how to use these integers to not use two errors with the same number. And I solved it. Some numbers were reserved to some things in one class, but I used e.g. number "1" in action, form and business classes. It was good for some time (although it has mentioned problem), but it was also very bad if I wanted to know where this error was raised. Now I use following solution: Instead of integer I use string: <ZNF_class_name_in_shorter_version>_<function_name>_<error_code_name> e.g. - $logs->addCriticalError('Form_FacList_validate_UniNameNotValid', $localization['uni']->get('error','UniNameNotValid')); [form class] - $_REQUEST[ZNF::LOGGING_INDEX]->addError('FacAction_facAdd_FacAddFail', $localization['uni']->get('error','FacAddFail')); [action class] - $logs->addCriticalError('FacDAO_getFaculties_SqlParamsNotValid', $localization['znf']->get('error','SqlParamsNotValid')); [business class] and current, a little better solution: - $logs->addCriticalError('MajDAO_' . __FUNCTION__ . '_SqlParamsCheckingError', $localization['znf']->get('error','SqlParamsCheckingError')); [business class] If I turn off Smarty debug console I have all messages and errors listed. I also see error key, so it is easy to find where it was raised. In first solution the only thing I have to do it is to run search engine and find e.g. string "Form_FacList_validate_UniNameNotValid". This is very good solution with some database errors (wrong syntax or something). The second is that it has some advantages: I don't have to take care about function name, but it has some disadvantages: it is not easy to find that error as in previous example. I could place here class name by using "__CLASS__", but ZNF class names are very long, so I'm using shorer version: e.g. "FacDAO", which means: University_Business_FacultyDAO class. It is much shorter, isn't it? If you find some time I'd like to hear what do you think about that idea. Best regards, Tomasz Kuter ---------------------------------------------------------------------- Horror na niebie >> Zobacz >>> http://link.interia.pl/f1adf |