How do you know the email addresses are bad? Wouldn't it be better to validate them when they're entered into the system? Either way, the Send method shouldn't validate the address. A method should do one thing. One named "SendEmail" tells me that it sends emails, not that it validates addresses, not that it counts how many it can send.
I don't know what all the class does, but a class should also have one purpose. I only have a little information to go on about your design and needs, but I'd have a method that validates the address, one that determines how many it can send, then for each one of those, call the SendEmail method.
>Craig,
>
>I think I misunderstood what you were trying to tell me. I thought you were saying that my code should trap the error and display it, not that I should restructure the way my code is written so that I do not hav eto return error codes and messages when things go wrong.
>
>Let me explain what I am doing and see if you can tell me how to approach it.
>
>My code is meant to send emails out. I need to:
>
>1. Count how many emails are sent and display this count on completion.
>
>2. Trap any email addresses that are badly formatted and, when the process is complete, display them so they can be fixed.
>
>3. Display any error message that occurs when sending (such as if the daily sending quota has been exceeded).
>
>>
>>>Hi,
>>>
>>>I'm trying to adjust a method so I can get two bits of information out of it. Previously I was just returning an error code, now I would like to return an error message along with the code. I found one way to do this is to use out parameters, so I adjusted my methods definition to this:
>>>
>>>
public void SendEmails(Guid emailPK, string subject, string html, out int errorCode, out string errorMessage)
>>>
>>>When I try calling this method like this:
>>>
>>>
int errorCode;
>>>string errorMessage;
>>>emailNotifications.SendEmails(emailPK, email.blk_subject, email.blk_html, out errorCode, out errorMessage);
>>>
>>>I get this error:
>>>
>>>"No overload for method 'SendEmails' takes 5 arguments"
>>>
>>>Maybe it's too early in th emorning for me but I think I'm counting correctly.
>>>
>>>Can anybody help enlighten me, please?
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer