[thelist] [ASP.NET] best practice error handling

Les Lytollis leslytollis at dimensions-corporatewear.co.uk
Thu Apr 15 03:40:54 CDT 2004

Thanks for the input.

Ken, from your link to MSDN, what I was I trying to get at was this:

"...you should not use exceptions as a means to provide your intended
functionality. For example, a user might enter an invalid user name or
password while logging on to an application. While this is not a
successful logon, it should be a valid and expected result, and
therefore should not throw an exception. However, an exception should be
generated if an unexpected condition occurs, such as an unavailable user
database. Throwing exceptions is more expensive than simply returning a
result to a caller. Therefore they should not be used to control the
normal flow of execution through your code. In addition, excessive use
of exceptions can create unreadable and unmanageable code."

So, in the hope that I can pay back some of the help I have had from the
list, here is my solution for anyone who is intersted:

//At the data layer, rather than throw an exception, wrap the code for
intended functionality.
if (dsProductSetID.Tables[0].Rows.Count > 0)
{strRetVal =
else {strRetVal = Core.AppException.NO_RECORDS;}
return strRetVal;

//At the business layer, check for this known result of empty search:
if (productSetID != Core.AppException.NO_RECORDS) 
return dsProductSet;

//At the presentation layer, check for an empty DataSet and produce a
friendly user message
if (dsProductSet.Tables.Count > 0) 
Repeater1.DataSource = dsProductSet;
} else {Response.Write("no match!");}

Les Lytollis
Web Developer 

> Sorry for the bum steer. What you might return is an empty 
> dataset (for example).
> Take a look at this: 
> http://msdn.microsoft.com/library/default.asp?url=/library/en-
> us/dnbda/html/exceptdotnet.asp
> > you could choose to add a repeater, or a label,
> > depending on what is returned (dataset or string).
> If my method is:
> public DataSet GetProductSet() {}
> How do I return a string?

********************Confidentiality Notice & Disclaimer ***********************
This message, together with any attachments, is for the confidential and exclusive use of the addressee(s).
If you receive it in error, please delete the message and its attachments from your system immediately and notify us by return e-mail.
Do not disclose, copy, circulate or use any information contained in this e-mail.

(1) Whilst we have taken reasonable precautions to ensure that any attachment to this e-mail has been swept for viruses, we cannot accept liability for any damage sustained as a result of software viruses and would advise that you carry out your own virus checks before opening any attachment.
(2) The sender shall remain solely accountable for any statements, representations or opinions that are clearly his or her own and not made in the course of employment.

More information about the thelist mailing list