- Home
- LLBLGen Pro
- Architecture
Error handle
Joined: 01-Dec-2003
Just looking for some advice on something....
Lets say I have my BL that wraps up the calling of my ActionStored procedures. I put the actual call inside a try catch block. If I get an error I log it to the database and return -1
So now in my Presentation layer what do I do.... do I
- See that the value is -1 and redirect to the error log ... or
- Should I re-throw the error for my PL to handle
Bert
Joined: 21-May-2004
I have my save function return false, and I write to the eventlog.
EventLog ev = new EventLog("PurchaseOrders");
ev.Source = "PurchaseOrders_BLL";
ev.WriteEntry(
ex.Message +
" -The error occured in EmployeeEntity GetEmployee(string)"
,EventLogEntryType.Error);
I am not sure if I plan on keeping this code, as it seems the stupid eventlog fills up sometimes and throws goofy errors. You could always dump errors to xml files using the Exception Application block.
Joined: 04-Feb-2004
bertcord wrote:
Just looking for some advice on something....
Lets say I have my BL that wraps up the calling of my ActionStored procedures. I put the actual call inside a try catch block. If I get an error I log it to the database and return -1
So now in my Presentation layer what do I do.... do I
- See that the value is -1 and redirect to the error log ... or
- Should I re-throw the error for my PL to handle
Bert
Here is how I deal with this: If the exception that I get from the BL is expected, then I will define a custom exception (with a friendly message) and use the original exception in the inner exception of my custom exception, then I throw it. If it is an unplanned exception, I just throw it.
So in your case, I would log it wherever you need to log it, then format it on the PL side.
My approach might be overkill.
My custom exception:
Namespace CustomExceptions
''' -----------------------------------------------------------------------------
''' Project : eMason.Web.Facade
''' Class : Web.Facade.CustomExceptions.UnspecifiedEmployeeException
'''
''' -----------------------------------------------------------------------------
''' <summary>
''' This exception is thrown when an employee is authenticated but the credentials
''' in the security system have not been mapped to an employee in the current application
''' </summary>
''' <remarks>
''' </remarks>
''' <history>
''' [cbertolasio] 6/30/2004 Created
''' </history>
''' -----------------------------------------------------------------------------
<Serializable()> _
Public Class UnspecifiedEmployeeException
Inherits eMason.Web.Facade.CustomExceptions.BaseEMasonException
Private Const _message As String = "The user with User ID: {0} has authenticated but has not been assigned to an employee in the EMA system."
Public Sub New()
MyBase.New()
End Sub
Public Sub New(ByVal message As String, ByVal exception As Exception)
MyBase.New(message, exception)
End Sub
Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
MyBase.New(info, context)
End Sub
Public Sub New(ByVal userId As String)
MyBase.New(String.Format(CurrentCulture.InvariantCulture, _message, userId))
End Sub
End Class
End Namespace
Here is a method in my Facade Object:
''' -----------------------------------------------------------------------------
''' <summary>
''' Use the return value from this method to create a user info ticket for the EMA
''' system.
''' </summary>
''' <param name="userId">The primary key of the eMason security account that is attempting to access EMA</param>
''' <returns>An employee entity</returns>
''' <remarks>
''' </remarks>
''' <history>
''' [cbertolasio] 6/30/2004 Created
''' </history>
''' -----------------------------------------------------------------------------
Public Shared Function GetUserInfo(ByVal userId As Integer) As EntityClasses.Employees1Entity
Dim userInfos As New HelperClasses.EntityCollection(New FactoryClasses.Employees1EntityFactory)
Dim pred As New PredicateExpression(FactoryClasses.PredicateFactory.CompareValue(Employees1FieldIndex.UserID, ComparisonOperator.Equal, userId))
Dim bucket As New RelationPredicateBucket
bucket.PredicateExpression.Add(pred)
Dim _emaData As New EMAData(False)
_emaData.FetchEntityCollection(userInfos, bucket)
If userInfos Is Nothing Then
Throw New Exception(String.Format(CurrentCulture.InvariantCulture, "Unable to locate user info for the current user id: {0}", userId))
End If
If userInfos.Count <= 0 Then
Throw New CustomExceptions.UnspecifiedEmployeeException(userId)
ElseIf userInfos.Count > 1 Then
Dim sMsg As String = String.Format(CurrentCulture.InvariantCulture, "The eMson Security system returned more than one user was found for user id:{0}.", userId)
Throw New CustomExceptions.DataIntegrityViolationException(sMsg)
Else
Return userInfos(0)
End If
End Function
Also, bert, I know youre pretty involved in DNN, if you have time for some side work, can you get with me via email? I have questions for you.