DBConcurrencyException
Old forum URL: forums.lhotka.net/forums/t/1961.aspx
Nemisis posted on Wednesday, December 13, 2006
Hi everyone, hope everyone is looking forward to xmas break! i am!
probably a simple question for someone, but i have coded in concurrency checks into my code, and a DBConcurrencyException is raised, but Csla wraps exceptions?
How can i tell if a DBConcurrencyException occurred on my website/Windows Form?
At the moment the code is as follows
Try
Company.Save
Catch Ex as DBConcurrencyException
MsgBox "Concurrency Exception"
Catch Ex as Exception
MsgBox "Update Error in database"
End Try
But ex on DBConcurrencyException is never caught, anbd always caught on Ex as Exception.
Would really appreciate some help
Thanks in advanced.
Bayu replied on Wednesday, December 13, 2006
Yes: csla does wrap exceptions in some places.
Just, recursively check the InnerException and StackTrace properties for additional clues. Also, some of the exceptions thrown by csla have a BusinessException property that contains the wrapped exception.
Bayu
RRorije replied on Wednesday, December 13, 2006
I agree,
I think the error handling could be something like this, I typed this without testing, directly in the editor, so some things may be named slightly different.
Try
Company.Save
Catch Ex as CSLA.DataportalException
If typeof(Ex.BusinessException) is gettype(DBConcurrencyException) Then
MsgBox(Ex.BusinessException.Message)
Else
'Other exception
End If
Catch Ex as CSLA.ValidationException
MsgBox Company.ValidationRules.ToString()
End TryBayu replied on Wednesday, December 13, 2006
I merely meant something like this:
Public Shared Sub Handle(ByVal ex As Exception)
Print("Exception Occurred (" & DateTime.Now.ToShortTimeString & ")")
Report(ex)
End Sub
Private Shared Sub Report(ByVal ex As Exception)
Dim msg As New Text.StringBuilder
msg.AppendLine("Type of Exception: " & ex.GetType.ToString)
msg.AppendLine(ex.Message)
msg.AppendLine()
msg.AppendLine(ex.StackTrace)
Print(msg.ToString)
If TypeOf ex Is DataPortalException Then
Dim dpex As DataPortalException = DirectCast(ex, DataPortalException)
If Not IsNothing(dpex.BusinessException) Then
Report(dpex.BusinessException)
End If
End If
If Not IsNothing(ex.InnerException) Then
Report(ex.InnerException)
End If
End Sub
Private Shared Sub Print(ByVal msg As String)
Debug.WriteLine(msg)
End Sub
In this case also all inner-exceptions and business-exceptions are reported in full.
Bayu
Copyright (c) Marimer LLC