[phobos] isemail error handling

Jacob Carlborg doob at me.com
Sat Mar 5 03:07:29 PST 2011


The PHP version returns "true", "false" or a code indicating why the email address isn't valid. In addition to that it has an out parameter, an array, containing among other things the local and the domain part of the address. I was thinking that I either keep it like that, with an out parameter, or return a struct with the information.

If I return a struct I was thinking it would contain the following fields:

bool valid;
string local;
string domain;
int statusCode/reasonCode;

And also make the struct implicitly convertible to bool. Would that be too much to return by value?

-- 
/Jacob Carlborg

On 5 mar 2011, at 00:46, Jonathan M Davis wrote:

> On Friday, March 04, 2011 15:25:05 Jesse Phillips wrote:
>> Is there a reason to make them exceptions? The whole point is to tell
>> you if it is or is not a function. I would not consider it an error
>> code more a "reason code" (why it wasn't an email address).
> 
> Those aren't exceptions then. An exception would be for an error of some kind in 
> running your function. But there is no error in running your function. It's 
> validly running and telling you that the input was not a valid e-mail address. 
> There's no error there. So, it looks like it either needs an additional out 
> parameter or to return a tuple with whether the address is valid and the reason.
> 
> Since there are likely a lot of cases that the programmer doesn't care why the 
> e-mail address is invalid, you should probably create two versions of the 
> function (probably one which wraps the other), where one has an out parameter 
> for the reason that the address is invalid and the other doesn't.
> 
> - Jonathan M Davis
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos



More information about the phobos mailing list