|
Posted by burgermeister01 on 08/16/07 14:51
On Aug 16, 2:38 am, Yarco <yarc...@gmail.com> wrote:
> When i am coding something, i always need to do some error control on
> it.
> For example:
>
> <?php
>
> function check()
> {
> // the following vars from somewhere
> if (empty($username))
> {
> $error['username'] = 'empty user name';
> return false;
> }
> if (//...)
> {
> }
> return false;
>
> }
>
> try
> {
> // to add a record}
>
> catch(Exception $e) // but failed, because you can't add record again
> some column is uniq.
> {
> $error['db'] = $e->getMessage();
>
> }
>
> ?>
>
> So $error will contain something like:
> 'db' => "SQLSTATE[23000]: Integrity constraint violation: 1062
> Duplicate entry '1-5' for key 'rate_guid_accountId'"
>
> But i want to let user know they do not do such thing but now such
> professional words.
> How can i do it?
A good approach I've used in the past is to have two arrays for error
message; one for developers and one for users. Then you can do
something more like this:
try
{
// to add a record
}
catch(Exception $e) // but failed, because you can't add record again
some column is uniq.
{
$dev_error['db'] = $e->getMessage();
$user_error['db'] = "I'm sorry, that user name is already taken.
Please try again.";
}
That way in your debugging output you can see exactly what went wrong
and at the same time you can have a more friendly message for end
users, and without giving away too many details.
Navigation:
- Next in forum: address of function or a virtual function
- Prev in forum: Biggest worldwide free Video multi language web , Travel, Sports, Racing cars , Massages techniques, Games , Fashions, Jokes , Top models , Free online IT learning , 5000 links, 250 free online TV , 50000 music video, nice landscapes , Health , Fl
- Thread view: Re: database exception message to user-end information
[Reply to this message]
|