I don't know what is your server technology. CF, JAVA, .NEt or PHP.
On PHP (amfphp) we are comfortable with throwing Exceptions new
Exception("your message",your_code) but if returning a string is not
enough, you can return a JSON_encoded object.
throw exception will we handled by a faultEvent on Flex RemoteObject and
faultCode determines your switch/case statement.
Using "Exceptions" on server-side make your code more reusable no matter
the client.
Also if you are working with objects that execute complex tasks (with
your approach) you always return a result no mater if the executed task
is completed or not. So You always need to check if $result->isok
instead of using try{} catch {} .
Imagine this common scenario "login":
Few things can go wrong (a saber)
1. can't connect to DB.
2. can't connect with the wrong user.
3. can't connect with the wrong password.
4. cant' connect due the account expired.
You can do something like (code snippet from amfphp project)
function doLogin ($user, $name) {
try {
$conn = $db->connect($user,$name);
try {
return $conn->executeStoreProcedure('get_User_Details', $user);
} catch($e Exception) {
throw new Exception ('Something go wrong here, maybe user not founded or
account expired.',405);
}
} catch ($e Exception) {
throw new Exception ('Cant connect to the DB host or invalid
login/password',404);
}
}
In this case, no matter if you execute this code from a HTML form, unit
testing scripts or FLEX remote Object.
You will notice that something go wrong but is well explained.
I hope this clarify.