using custom exceptions when DAL return no rows

J

Jeff

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?
 
S

sloan

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.
 
A

Arne Vajhøj

Jeff said:
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
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...

It should.

Could you post an small simple example showing the problem ?

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top