New properties of Exception descendant are not shown in snapshot viewer

  • Thread starter Thread starter Stanislaw Tristan
  • Start date Start date
S

Stanislaw Tristan

Problem:
I created a custom exception that inherits from Exception and added a some
of new properties. All new properties filled in the constructors. When I
throwing this custom exception and go to the snapshot viewer the last shows
only properties of Exceptions, the new properties are not shown.
Question:
How to show new properties of Exception-descendants in the snapshot viewer
(such as, for example, SqlException shows Procedure, Line and etc.)?
 
It should work!!!.

you are trying to use the viewer in catch() statement? is your catch
statement declared the exception object of Type MyCustomException?
//catch(MyCustomException ex)
//and not
catch(Exception ex)

Regards,
 
Yes, of cource, MyCustomException

singhhome said:
It should work!!!.

you are trying to use the viewer in catch() statement? is your catch
statement declared the exception object of Type MyCustomException?
//catch(MyCustomException ex)
//and not
catch(Exception ex)

Regards,
 
I tried it on my system and it was showing new properties in the
visualizer!
can u send ur code of mycustomexception?

Regards,
 
This a code of Exception:

Imports Zestad.Common.Validation

Namespace Exceptions

''' <summary>
''' Occurs if one or more business rules validation breaks
''' </summary>
<Serializable()> _
Public Class ValidationException : Inherits Exception

Private varErrors As List(Of ValidationError)
''' <summary>
''' List of validation errors
''' </summary>
Public ReadOnly Property Errors() As List(Of ValidationError)
Get
Return varErrors
End Get
End Property

Private varTestProperty As string
''' <summary>
''' This is a test property for test catching and showing in the visualizer
''' </summary>
Public ReadOnly Property TestProperty() As string
Get
Return varTestProperty
End Get
End Property

''' <summary>
''' Constructor of this class
''' </summary>
Public Sub New(ByVal Message As String, Test as string, ByVal Errors As List(Of ValidationError))
MyBase.New(Message)
Me.varErrors = Errors
Me.varTestProperty=Test
End Sub

''' <summary>
''' Returns bulleted string with error descriptions
''' </summary>
Public Overloads Function ToString(Optional ByVal Bullet As String = "", Optional ByVal IncludeMessage As Boolean = False) As String
If Me.Errors.Count = 0 Then Return ""
Dim ErrorsArray(Me.Errors.Count) As String
For i As Integer = 0 To Me.Errors.Count - 1
ErrorsArray(i) = Bullet & Me.Errors(i).Cause
Next
If IncludeMessage = True Then
Return Me.Message & StrDup(1, Chr(13) & Chr(10)) & Join(ErrorsArray, Chr(13) & Chr(10))
Else
Return Join(ErrorsArray, Chr(13) & Chr(10))
End If
End Function
End Class

End Namespace

And this is a block catch:

try
....some_code...
throw new ValidationException ("test_message", "test_property_value", varErrors)
....
catch ex as ValidationException
throw ex ' visualizer shows only properties of parent class (Exception), but not ValidationException
end try
 
Back
Top