Trapping Save() Errors


Author
Message
StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Looks good, just make sure that when you throw the exception from within the handlers, that you include the supplied exception as an inner exception in case you need to get back to the stack trace some how.
choyt
choyt
StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)
Group: Forum Members
Posts: 78, Visits: 246
I really appreciate all your help. This is what I finally came up with. I'm going to put this on all of our base business objects.

Public Overrides Function Save(ByVal IsTransactional As Boolean) As MicroFour.StrataFrame.Data.SaveUndoResult

Try

Dim r As MicroFour.StrataFrame.Data.SaveUndoResult = MyBase.Save(IsTransactional)

If r = MicroFour.StrataFrame.Data.SaveUndoResult.AbortedWithBrokenRules Then

Call Utility.SystemUtilities.ErrHandler.BrokenRulesHandler(Me.BrokenRules)

ElseIf r = MicroFour.StrataFrame.Data.SaveUndoResult.FailedWithExceptions Then

Call Utility.SystemUtilities.ErrHandler.SaveFailedHandler(Me.TableName)

Else

Return r

End If

Catch ex As Exception

Call Utility.SystemUtilities.ErrHandler.SaveFailedHandler(ex)

End Try

End Function

The 2 Handler functions basically write to the event log and then rethrow a custom exception to the presentation layer.

choyt
choyt
StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)
Group: Forum Members
Posts: 78, Visits: 246
Cool...thanks Ben
StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
I'm not tracking on this part...

I was just saying that when you create a new business object from our template, it will inherit from BusinessLayer, so you will need to change it so that it inherits from your class, not BusinessLayer.  The base class that you create will be excactly like you mentioned... it's a basic business object (that itself will inherit from BusinessLayer).

StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Well, actually, the business object isn't going to ever return FailedWithExceptions from save()... Ermm

If an exception is encountered from within the save, then the exception will just be bubbled up if the ErrorSavingMode is FailOnError and the return value will be CompletedWithExceptions if the ErrorSavingMode is ContinueOnError.  If ContinueOnError is used, then yes, the ErrorSaving event will contain the exceptions thrown. 

So, the FailedWithExceptions is used for the SaveByForm() method, not the Save() method.  So, if you're going to be saving all of the business objects at once through the form's Save() method, then I you would want to override the SaveByForm() method and do the same thing (but I don't think that one is overridable, so if you're saving through the form's Save() method, then we might need to work out something different).

choyt
choyt
StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)
Group: Forum Members
Posts: 78, Visits: 246
Hi Ben

I'm not tracking on this part...

Just make sure to change the Inherits line (or the : line) when you create a new business object from our template.

I generally create my own base classes using your templates then inherit from those.

choyt
choyt
StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)
Group: Forum Members
Posts: 78, Visits: 246
Thanks Ben

Is the ErrorSaving event the only place I can examine the exceptions that cause FailedWithExceptions?

 


StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Yep, looks good to me.  Centralizes everything nice and neat.  Just make sure to change the Inherits line (or the : line) when you create a new business object from our template.
choyt
choyt
StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)StrataFrame Novice (92 reputation)
Group: Forum Members
Posts: 78, Visits: 246
Hi Ben

This is what I've come up with...what do you think?

Public Overrides Function Save(ByVal b As Boolean) As MicroFour.StrataFrame.Data.SaveUndoResult

Dim r As MicroFour.StrataFrame.Data.SaveUndoResult

r = MyBase.Save(b)

If Not (r = MicroFour.StrataFrame.Data.SaveUndoResult.Success OrElse _

r = MicroFour.StrataFrame.Data.SaveUndoResult.Cancelled OrElse _

r = MicroFour.StrataFrame.Data.SaveUndoResult.CompletedWithExceptions) Then

Select Case r

Case MicroFour.StrataFrame.Data.SaveUndoResult.AbortedWithBrokenRules

Dim strJson As String = LitJson.JsonHelper.WriteJsonString(Me.BrokenRules)

Utility.SystemUtilities.ErrHandler.WriteEventLog(strJson, "", Diagnostics.EventLogEntryType.Error)

Throw New Exceptions.BrokenRulesException(strJson)

Case MicroFour.StrataFrame.Data.SaveUndoResult.FailedWithExceptions

Throw New ApplicationException()

End Select

End If

End Function

StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Well, the ErrorSaving event only catches exceptions that are caused during the save, and only if the ErrorSavingMode is set to ContinueOnError.  Your best bet would be to create a BoBase class and override the OnBusinessRulesChecked method.  If the business rules are broken, then throw your exception containing the business rules. 

Another option would be to create the BoBase class and override Save().  Call MyBase.Save() and check the return value within your own Save() and check the select case there.  You could even show your form with the broken rules there if you don't mind taking that portion of the UI out of the UI...

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search