title: Safest way to check for integer
body: <p>This is probally more of an elegance question than functionality. I am looking for the absolutely safest way to check for an integer from a string and an object,</p>
  
  <p>Using most of the built in functions for this in .net seem to generate a first chance exception, displayed in the Immediate window, and over time they just build up. what are the implications of these exceptions as they don't seem to affect the operation of the system.</p>
  
  <p>Here are my two attempts, both feel clunky and I know there has to be a better way than using VB.IsDBNull and Integer.TryParse... Or am I just being anal.</p>
  
  <p>(to integer from object)</p>
  
  <pre><code>    Dim nInteger As Integer = 0
      If oData Is Nothing OrElse VB.IsDBNull(oData) Then
      Else
          If bThrowErrorIfInvalid Then
          Else
              On Error Resume Next
          End If
          nInteger = CType(oData, Integer)
      End If
      Return nInteger
  </code></pre>
  
  <p>(to integer from string)</p>
  
  <pre><code>    Dim nInteger As Integer = 0
      If sText Is Nothing Then
      Else
          If bThrowErrorIfInvalid Then
          Else
              On Error Resume Next
          End If
          Integer.TryParse(sText, nInteger) 
      End If
      Return nInteger
  </code></pre>