Today I had a nice talk chat with a friend of mine. We covered few aspects of web development.
He criticised my application errors handling approach, basically if I need to check user permission to perform an action, I do the following:
// My little function
function check_user_perms($user)
{
// @returns boolean
// checking is user is permitted to perform an action
return ($something > 1) ? TRUE : FALSE; // of course it returns true/false, not null
}
// place where I need to check user permission
// please note that following lame snippets are meant to show you my approach
if( check_user_perms($user_id) )
{
// perform the action
}
else
{
echo 'You have no permission to perform this action.';
}
He said, I should use exceptions. So I started to read and think I learned good exceptions practices.
There are only few things that needs clarification:
1. Should I use exceptions for everything in web application?
2. If so, how to show a message to user on production?
3. What approach would you suggest?