exception handling using enterprise library


G

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
 
Ad

Advertisements

A

Alvin Bruney [MVP]

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.
 

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