title: How to force an Exception if a Developer uses a property Incorrectly
body: <p>I am trying to setup a few fixes in some code that have caught me out, and am trying to get some exceptions to spit out if the developer trys to access a property where rules haven't been met.</p>
  
  <p>nb. Lots of this class has been omitted for Clarity. </p>
  
  <pre><code>myobject = new POSTerminalList(mCommonManagers)
  
  ' This should throw an error which it does but is out of scope. 
  Log.Write(myobject.Current.Description)
  </code></pre>
  
  <p>Currently I'm throwing an exception, but this loses the calling function (which is really where the problem exists).</p>
  
  <p>Is there some way to protect a property like this so that if the developer incorrectly uses the property, that you know where to look rather than in this class.</p>
  
  <p>Whilst this code is VB.Net i'm interested in the Design approach rather than language so a C# implemention would also work for me.</p>
  
  <pre><code>&lt;DebuggerDisplay("{mCode}", Name:="{mDescription}")&gt; _
  Public Class POSTerminalList
  Inherits SortedList(Of Integer, POSTerminal)
  
      Private mCurrentTerminal As POSTerminal
      Private mCurrentTerminalNumber As Integer
  
      Private Sub New()
          mFullList = New SortedList(Of Integer, POSTerminal)
      End Sub
  
      Public Sub New(ByVal theManagers As IPSBusiness.CommonManagers)
          Me.New()
      End Sub
  
      ''Internal thread that is assessing things and calling this method.
      Private Sub SetCurrentTerminal()
          If mCurrentTerminalNumber = 0 Then
              mCurrentTerminal = Nothing
          Else
              If Me.ContainsKey(mCurrentTerminalNumber) Then
                  mCurrentTerminal = me.Item(mCurrentTerminalNumber)
              Else
                  mCurrentTerminal = Nothing
              End If
          End If
      End Sub
  
      Public ReadOnly Property Current() As POSTerminal
          Get
              If mCurrentTerminal Is Nothing Then 
                  Throw New POSTerminalMissingException(
                      "Attempt to use the Current Terminal without a " +
                      "valid current terminal. This is a developer error.")
              Return mCurrentTerminal
          End Get
      End Property
  
  End Class
  </code></pre>