Hey,
I have the following code in my files:
In Class Customer.Page:
Try
If Not SiteContent.CurrentUser(False) Is Nothing Then
If Not SiteContent.CurrentUser(False).IsAdministrator OrElse SiteVariables.CustomerMode Then
SiteContent.PageViewManager.Create(New List(Of Control))
End If
Else
SiteContent.PageViewManager.Create(New List(Of Control))
End If
Catch ex As Heritage.Web.Content.Items.Exceptions.ExceptionGroup
My.Response.Write(ex.Message & "<br />" & ex.StackTrace & "<br />")
End Try
In Class Item
Public Overridable Sub CheckValidity()
'If the item is recycled then return true'
If IsRecycled() Then
Exit Sub
End If
'ExceptionGroup to store all exceptions which are thrown due to invalid data.'
Dim ExceptionGroup As New Exceptions.ExceptionGroup
Try
'Checks if the item already exists'
Exists()
Catch ex As Exception
'Add any exception as a result of this function to the ExceptionGroup'
ExceptionGroup.AddException(ex)
End Try
'Check each attribute - add any exception which occurs as a result of validating their values to the ExceptionGroup'
For Each Attribute As Items.Attribute In GetAttributes
If TypeOf Attribute Is StringAttribute Then
Dim StringAttribute As StringAttribute = Attribute
Try
If Not StringAttribute.Validate(StringAttribute.Value) Then Throw New Exceptions.ItemExceptions.RequiredFieldException(StringAttribute.Name)
Catch ex As Exception
ExceptionGroup.AddException(ex)
End Try
ElseIf TypeOf Attribute Is IntegerAttribute Then
Dim IntegerAttribute As IntegerAttribute = Attribute
Try
If Not IntegerAttribute.Validate(IntegerAttribute.Value) Then Throw New Exceptions.ItemExceptions.RequiredFieldException(IntegerAttribute.Name)
Catch ex As Exception
ExceptionGroup.AddException(ex)
End Try
ElseIf TypeOf Attribute Is DateTimeAttribute Then
Dim DateTimeAttribute As DateTimeAttribute = Attribute
Try
If Not DateTimeAttribute.Validate(DateTimeAttribute.Value) Then Throw New Exceptions.ItemExceptions.InvalidFormatException(DateTimeAttribute.Name)
Catch ex As Exception
ExceptionGroup.AddException(ex)
End Try
End If
Next
'Rollback the transaction if the ExceptionGroup contains any Exceptions'
If ExceptionGroup.Exceptions.Count > 0 Then
RollbackTransaction()
Throw ExceptionGroup
End If
End Sub
I know this may all seem complicated, but you should be able to deduce that the first chunk of code catches the ExceptionGroup thrown in the second chunk of code.
This is basically part of a system where objects are created from rows in the database as and when one of the objects is first needed (i.e. many objects, of a specific type, is created for each row and then data is extracted for each one only when it is first requested. Each object stores an instance of DataRow from which the attributes within the object extract the piece of data they need when the value of the attribute is first requested).
My point is that it is a system I have made from scratch with no third party code and not using Linq or any other fancy stuff like that (nor do I want to, before anyone says to switch to Linq or anything like that).
Anyway the ExceptionGroup, as you can tell, is populated by other exceptions which are thrown by validation of each attribute.
Now heres the problem. On running the first chunk of code without the try catch statement, it throws a horrible red and yellow error screen. However with the try catch statement, it loads perfectly.
Does anyone have any idea what could be causing this weird behaviour? Has anyone ever encountered this behaviour before?
Thanks in advance.
Regards,
Richard