Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / December 2007

Tip: Looking for answers? Try searching our database.

using custom exceptions when DAL return no rows

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeff - 06 Dec 2007 21:47 GMT
Hey

.NET 2.0

I'm developing an application (n-tier, data acces layer (DAL), bizlayer and
presentation layer)

If for example in the DAL a stored procedure call returns no rows then I
want an exception to be thrown. So I created an custom exception called
NoRowsException and throws it.

When I tryed this the app terminated unexpectedly, because in the try /
catch block I didn't test if the exception was NoRowsException.. I had
Exception there and thought Exception took all Exceptions, but it didn't...
so it looks like I also have to test if it's an NoRowsException:
try
{
   //todo
}
catch (NoRowsException norows) {}
catch (Exception exp)

any thoughts about this? could this be done in a better way?
sloan - 06 Dec 2007 21:57 GMT
Granted, getting feedback from the RDBMS is a little tougher than just
DotNet code....

But here is a great resource:
http://blogs.msdn.com/kcwalina/archive/2005/03/16/396787.aspx

:"exceptions should be exceptional"...thus if you expect to have no rows
.....then its probably not exceptional, and you should code to handle zero
row.

if it is exceptional....like the GUI came up with a list of employees...and
while you're looking at that screen.....somebody deletes the employee..and
you go to edit JohnSmith...you get zero rows...then that would be
exceptional.

> Hey
>
[quoted text clipped - 19 lines]
>
> any thoughts about this? could this be done in a better way?
Arne Vajhøj - 07 Dec 2007 00:34 GMT
> I'm developing an application (n-tier, data acces layer (DAL), bizlayer and
> presentation layer)

3-layer not n-tier.

> If for example in the DAL a stored procedure call returns no rows then I
> want an exception to be thrown. So I created an custom exception called
[quoted text clipped - 3 lines]
> catch block I didn't test if the exception was NoRowsException.. I had
> Exception there and thought Exception took all Exceptions, but it didn't...

It should.

Could you post an small simple example showing the problem ?

Arne

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.