title: Non-terminating Error Handling - Difference between if $Error.count and $ErrorActionPreference = 'stop'
body: <p>I need to handle a non-terminating error in a powershell script. What is the most efficient way to this?</p>
  
  <p>To set <code>$ErrorActionPreference</code> variable to stop and use try/catch</p>
  
  <pre><code>$ErrorActionPreference = 'stop'
  try{
      functionThatCanFail
  }catch{
      #Do Stuff
  }
  </code></pre>
  
  <p>Or to clear <code>$Error</code> variable and then evaluate if it is populated</p>
  
  <pre><code>$Error.Clear()
  functionThatCanFail
  if( $Error.Count -ne 0){
      #Do Stuff
  }
  </code></pre>