469,898 Members | 2,320 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

exception handling using enterprise library

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

Oct 12 '07 #1
1 2335
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
<testerwrote in message news:OM**************@TK2MSFTNGP03.phx.gbl...
>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

Oct 14 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Daniel Wilson | last post: by
1 post views Thread by Ray5531 | last post: by
16 posts views Thread by Chuck Cobb | last post: by
3 posts views Thread by Bruce One | last post: by
reply views Thread by =?Utf-8?B?UG9sbHkgQW5uYQ==?= | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.