Property values being retained?

  • Thread starter Thread starter Andy B.
  • Start date Start date
A

Andy B.

I was looking up something in msdn and found out that properties original
values should be retained in case it throws an exception. What does that
mean and how do you do that?
 
Andy B. said:
I was looking up something in msdn and found out that properties original
values should be retained in case it throws an exception. What does that
mean and how do you do that?


If it is in MSDN, then you should cite the reference so we can read in
context.

A guess is that it means something as follows:

Public Class Test
Private SqrtZ As Double
Private Z As Double
Public Property Height() As Double
Get
Return Z
End Get
Set(ByVal value As Double)
Z = value
SqrtZ = Math.Sqrt(value)
End Set
End Property
End Class

If you set the property Height to a negative value, the object would be in a
bad state because SqrtZ is not in agreement with Z after the exception
occurs. The recommendation would then be:

Public Class Test
Private SqrtZ As Double
Private Z As Double
Public Property Height() As Double
Get
Return Z
End Get
Set(ByVal value As Double)
try
dim sz as double = Math.Sqrt(value)
SqrtZ = sz
Z = value
catch
end try
End Set
End Property
End Class
 
Without knowing the original context, I would guess it means:

Temp = propertyvalue
Try
Set new property value
Catch
Exception "Invalid Property"
Message / Warning / Log
propertyvalue = Temp
Exception other
...
End Try
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top