Trapping Save() Errors


Author
Message
choyt
choyt
StrataFrame User (132 reputation)StrataFrame User (132 reputation)StrataFrame User (132 reputation)StrataFrame User (132 reputation)StrataFrame User (132 reputation)StrataFrame User (132 reputation)StrataFrame User (132 reputation)StrataFrame User (132 reputation)StrataFrame User (132 reputation)
Group: Forum Members
Posts: 78, Visits: 246
Hi Folks

I am currently doing something similar to the following on every save() I do.

Select Case Me.Save

Case MicroFour.StrataFrame.Data.SaveUndoResult.AbortedWithBrokenRules

Throw New BrokenRulesException(Me.BrokenRules)

Case MicroFour.StrataFrame.Data.SaveUndoResult.FailedWithExceptions

Throw New ApplicationException("The save failed.")

End Select

I trap for broken rules and bubble them up with one custom exception class, and throw exceptions for the other results. Because of this I wind up with an ugly Case statement for every save. Is there any reason not to move this logic to the ErrorSaving event of the business object's themselves to centralize this or is this just the best way to do it?

Thanks!

Clay


Replies
choyt
choyt
StrataFrame User (132 reputation)StrataFrame User (132 reputation)StrataFrame User (132 reputation)StrataFrame User (132 reputation)StrataFrame User (132 reputation)StrataFrame User (132 reputation)StrataFrame User (132 reputation)StrataFrame User (132 reputation)StrataFrame User (132 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 (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K 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.
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K 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).

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