using custom exceptions when DAL return no rows

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeff

    #1

    using custom exceptions when DAL return no rows

    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 (NoRowsExceptio n norows) {}
    catch (Exception exp)

    any thoughts about this? could this be done in a better way?


  • sloan

    #2
    Re: using custom exceptions when DAL return no rows

    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/archi...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.....some body deletes the employee..and
    you go to edit JohnSmith...you get zero rows...then that would be
    exceptional.




    "Jeff" <it_consultant1 @hotmail.com.NO SPAMwrote in message
    news:uaVuDGFOIH A.4948@TK2MSFTN GP02.phx.gbl...
    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 (NoRowsExceptio n norows) {}
    catch (Exception exp)
    >
    any thoughts about this? could this be done in a better way?
    >

    Comment

    • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

      #3
      Re: using custom exceptions when DAL return no rows

      Jeff wrote:
      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

      Comment

      Working...