Hi Folks
I am struggling along with my first few classes and some custom exceptions. If I have the following:
A) What happens to the newly created DeviceUnderTest object if currentDuts.Add() fails, is it destroyed again, or is it floating somewhere in memory?
B) For that matter what happens if New DeviceUnderTest() fails? Does .Add() also fail? I'm guessing yes, but in that case, if I want to filter the exceptions by type, which exception will 'ex' be, the one from New() or the one from .Add()?
Also;
C) Should the tests on a constructors arguments be before or after MyBase.New(), I assume if the tests are after, any exceptions they cause to be thrown would not have prevented the object from being created... Is that the case? (Or maybe it's totally irrelevant?)
i.e.
Thanks
I am struggling along with my first few classes and some custom exceptions. If I have the following:
vb Code:
Dim currentDuts As New Dictionary(Of Integer, DeviceUnderTest) Dim newDutKey As Integer = currentDuts.Count + 1 Try currentDuts.Add(newDutKey, New DeviceUnderTest(LocationBox.Text)) Catch ex As Exception '... End Try
A) What happens to the newly created DeviceUnderTest object if currentDuts.Add() fails, is it destroyed again, or is it floating somewhere in memory?
B) For that matter what happens if New DeviceUnderTest() fails? Does .Add() also fail? I'm guessing yes, but in that case, if I want to filter the exceptions by type, which exception will 'ex' be, the one from New() or the one from .Add()?
Also;
C) Should the tests on a constructors arguments be before or after MyBase.New(), I assume if the tests are after, any exceptions they cause to be thrown would not have prevented the object from being created... Is that the case? (Or maybe it's totally irrelevant?)
i.e.
vb Code:
Public Class DeviceUnderTest Public Sub New(argument As String) 'Should MyBase.New() go here... If argument = wrong Then Throw New wrongArgumentException Else myPrivateVar = argument End If 'Or should MyBase.New() go here? End Sub '... End Class
Thanks