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