C
CJM
I'm working on my first real VB.NET application; I come from a VB6/ASP
background, so obviously a lot of my previous best practice is obsolete.
I'm creating a simple app that will email customers in our database with a
standard mailshot. I'm wanting to handle situations where the user enters an
invalid (i.e. amlformed) email address; I can think of a dozen ways that I
could do it but I'd rather prefer to hear what people think is good
practice. I have some code that checks if the email is well-formed but it's
more a question of where and when to use it.
For example, I could:
- Raise an Exception in the Property Set code
- Check the email address in the main method for the mailing class, and
raise an Exception - ie. check immediately prior to sending the email.
- Not bother checking for well-formedness - just catch the Exception from
the System.Net.Mail components
- Plan D?
Much of what I have read encourages me to use Try/Catch/Finally, yet some
people reckon Exceptions are a lazy way to handle anticipated problems...
Any comments?
Another thing that struck me is the lack of an error number as such. For
example, isn't there a need to discriminate between different instances of
the same type of Exception? We could have two ArgumentExceptions that we
want to handle differently... Am I to assume that this is where custom
Exceptions are in order?
It also seems unusual that some much - and yet so little - information is
provided by the Exception. You get a message but not much else that is of
use (as far as this noob can see). For example, if I allow the
System.Net.Mail.MailMessage object to handle a malformed email address, I
get the following message "The specified string is not in the form required
for an e-mail address.". Obviously in testing I know when email address
(From/To/CC/BCC) is malformed, but how can I tell at runtime. I'm sure I
must be missing 'something' - I realise the journey from COM to .NET is
completed overnight.
Thanks in advance...
CJM
background, so obviously a lot of my previous best practice is obsolete.
I'm creating a simple app that will email customers in our database with a
standard mailshot. I'm wanting to handle situations where the user enters an
invalid (i.e. amlformed) email address; I can think of a dozen ways that I
could do it but I'd rather prefer to hear what people think is good
practice. I have some code that checks if the email is well-formed but it's
more a question of where and when to use it.
For example, I could:
- Raise an Exception in the Property Set code
- Check the email address in the main method for the mailing class, and
raise an Exception - ie. check immediately prior to sending the email.
- Not bother checking for well-formedness - just catch the Exception from
the System.Net.Mail components
- Plan D?
Much of what I have read encourages me to use Try/Catch/Finally, yet some
people reckon Exceptions are a lazy way to handle anticipated problems...
Any comments?
Another thing that struck me is the lack of an error number as such. For
example, isn't there a need to discriminate between different instances of
the same type of Exception? We could have two ArgumentExceptions that we
want to handle differently... Am I to assume that this is where custom
Exceptions are in order?
It also seems unusual that some much - and yet so little - information is
provided by the Exception. You get a message but not much else that is of
use (as far as this noob can see). For example, if I allow the
System.Net.Mail.MailMessage object to handle a malformed email address, I
get the following message "The specified string is not in the form required
for an e-mail address.". Obviously in testing I know when email address
(From/To/CC/BCC) is malformed, but how can I tell at runtime. I'm sure I
must be missing 'something' - I realise the journey from COM to .NET is
completed overnight.
Thanks in advance...
CJM