title: PowerShell error variable loses the content
body: <p>I have a quite big project with many functions in there.
  Just 2 questions:</p>
  <ol>
  <li>What would be here the &quot;best practice&quot; regarding Error-Handling? To use a local handling per Function, or use only one Error-Logging in the Main-Section?</li>
  <li>The tricky part (!), let's have a look at the strange Error behaviour in the function F_XXX: only $_ delivers an error message, $Error[0] is here empty! Strange enough, when I start the function F_XXX separately (cut out from the module), it behaves as expected, it means: $Error[0] gives an error back. The code:</li>
  </ol>
  <blockquote>
  <p>Blockquote</p>
  </blockquote>
  <pre><code>$ErrorActionPreference = &quot;Stop&quot;
  Function F1
  {
      try
      {
      # do something
      }
      catch
      {
          # 1. cascade Error to Main?
          # throw $Error[0].InnerException
          # or
          # local Error-Logging?
          write-MyErrorLogging -message $Error[0].InnerException
      }
  }
  
  
  
  Function F2
  {
      try
      {
          # do something
      }
      catch
      {
          # 1. cascade Error to Main?
          # throw $Error[0].InnerException
          # or
          # local Error-Logging?
          write-MyErrorLogging -message $Error[0].InnerException
      }
  }
  Function F_XXXXXX
  {
      try
      {
          cls
          write-host &quot;The install data is copied..&quot;
          $share = &quot;\\my_wrong_path\sql_sources\&quot; 
          Copy-Item $share -Destination $installDrive -Force -Recurse
      }
      catch
      {
          $Error[0] #here is nothing!
          $null -eq $Error[0] # here true
          $_.Exception # only here the error-message: wrong path!
      }
  }
  </code></pre>
  <blockquote>
  <p>Blockquote</p>
  </blockquote>
  <pre><code># here Main
  try
  {
      F1
      F2
      F_XXXXXX
  }
  catch
  {
      write-MyErrorLogging -message $Error[0].InnerException
  }
  </code></pre>
  <blockquote>
  <p>Blockquote</p>
  </blockquote>