exception handling using enterprise library

Discussion in 'ASP .Net' started by Guest, Oct 12, 2007.

  1. Guest

    Guest Guest

    I have an application that has a presentation later, business layer, and
    data layer. All three projects have their own exception policy, the "UI
    Policy", "BL Policy", "DL Policy", all of which will log the error in the
    application event logs. When a database error occurs such as a missing
    stored procedure, all three policies will log the event resulting in three
    different entries in the error. My boss says there is a way in the
    exception handling to turn these duplicate errors off, but I certainly can't
    find a way to do this. And logically these are not duplicate errors, they
    each use different policies and they each have a different stack recorded.
    Every single procedure in every project has the exception code as follows:

    Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex,
    "UI Exception Policy")
    If rethrow Then
    throw
    End If

    Until ultimately it gets back to the calling procedure, which also logs the
    event, so we could have 5 million entries for one error. Okay, slight
    exaggeration.

    My thought is we need to be more precise on how we handle these errors. The
    data layer is always bubbled up, so I wouldn't think we'd need the data
    layer errors, since the ui layer will. What is the proper way to do this?
    Some example code:

    Presentation Layer:
    Sub TestDatabaseConnection
    try
    Dim bl as new bl
    Dim ds as new Dataset
    ds = bl.UpdateData(connString, spUpdateStuff)
    Catch ex as exception
    Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex,
    "UI Exception Policy")
    If rethrow Then
    throw
    End If
    end try

    end sub

    Business Layer (bl)
    function UpdateData(connString, sp) as integer
    Dim dl as new dl
    return dl.ExecuteNonquery(connString, sp)
    Catch ex as exception
    Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex,
    "BL Exception Policy")
    If rethrow Then
    throw
    End If
    end try
    end function

    Data Layer (dl)
    function ExecuteNonQuery(connString, sp) as integer
    try
    Dim retval as integer
    retval = SqlDataAccess.ExecuteNonQuery(connString,
    commandtype.storedprocedure, sp)
    return retval
    Catch ex as exception
    Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex,
    "DL Exception Policy")
    If rethrow Then
    throw
    End If
    end try

    end fundtion
    Guest, Oct 12, 2007
    #1
    1. Advertising

  2. The idea is to always log at every level. In production, logging is usually
    turned off unless there is a problem. At this point, logging is turned on
    and trouble-shooting is easier with 5 million logged messages. Then, turn it
    back off.

    --
    Regards,
    Alvin Bruney
    ------------------------------------------------------
    Shameless Author Plug
    OWC Black Book 2nd Edition
    Exclusively on www.lulu.com/owc
    $24.99


    <tester> wrote in message news:...
    >I have an application that has a presentation later, business layer, and
    >data layer. All three projects have their own exception policy, the "UI
    >Policy", "BL Policy", "DL Policy", all of which will log the error in the
    >application event logs. When a database error occurs such as a missing
    >stored procedure, all three policies will log the event resulting in three
    >different entries in the error. My boss says there is a way in the
    >exception handling to turn these duplicate errors off, but I certainly
    >can't find a way to do this. And logically these are not duplicate errors,
    >they each use different policies and they each have a different stack
    >recorded. Every single procedure in every project has the exception code as
    >follows:
    >
    > Dim rethrow As Boolean =
    > ExceptionPolicy.HandleException(ex, "UI Exception Policy")
    > If rethrow Then
    > throw
    > End If
    >
    > Until ultimately it gets back to the calling procedure, which also logs
    > the event, so we could have 5 million entries for one error. Okay, slight
    > exaggeration.
    >
    > My thought is we need to be more precise on how we handle these errors.
    > The data layer is always bubbled up, so I wouldn't think we'd need the
    > data layer errors, since the ui layer will. What is the proper way to do
    > this? Some example code:
    >
    > Presentation Layer:
    > Sub TestDatabaseConnection
    > try
    > Dim bl as new bl
    > Dim ds as new Dataset
    > ds = bl.UpdateData(connString, spUpdateStuff)
    > Catch ex as exception
    > Dim rethrow As Boolean =
    > ExceptionPolicy.HandleException(ex, "UI Exception Policy")
    > If rethrow Then
    > throw
    > End If
    > end try
    >
    > end sub
    >
    > Business Layer (bl)
    > function UpdateData(connString, sp) as integer
    > Dim dl as new dl
    > return dl.ExecuteNonquery(connString, sp)
    > Catch ex as exception
    > Dim rethrow As Boolean =
    > ExceptionPolicy.HandleException(ex, "BL Exception Policy")
    > If rethrow Then
    > throw
    > End If
    > end try
    > end function
    >
    > Data Layer (dl)
    > function ExecuteNonQuery(connString, sp) as integer
    > try
    > Dim retval as integer
    > retval = SqlDataAccess.ExecuteNonQuery(connString,
    > commandtype.storedprocedure, sp)
    > return retval
    > Catch ex as exception
    > Dim rethrow As Boolean =
    > ExceptionPolicy.HandleException(ex, "DL Exception Policy")
    > If rethrow Then
    > throw
    > End If
    > end try
    >
    > end fundtion
    >
    >
    >
    Alvin Bruney [MVP], Oct 14, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. levon
    Replies:
    0
    Views:
    644
    levon
    Sep 28, 2005
  2. Replies:
    3
    Views:
    542
  3. Replies:
    3
    Views:
    391
    Tom Dyess
    Jan 20, 2005
  4. Replies:
    2
    Views:
    573
    Tom Dyess
    Jan 20, 2005
  5. Wade
    Replies:
    3
    Views:
    560
    =?Utf-8?B?TXVydGF6YQ==?=
    Jul 25, 2006
Loading...

Share This Page