title: Stop script and log error
body: <p>I have a powershell script that needs to read from a config file with a simple Get-Content cmdlet:</p>
  
  <pre><code> foreach ($s in Get-Content $config_file)
  </code></pre>
  
  <p>If the config file is not where it is supposed to be I want to stop the script and log the error.</p>
  
  <p>Is it possible to use the -ErrorAction with a cusom logging function with in the script?</p>
  
  <pre><code>foreach($s in Get-Content $config_file -ErrorAction mdie('Could not find config file')
  </code></pre>
  
  <p><em>mdie</em> is a logging function that logs the error and exits the script.</p>
  
  <p>Or is there a better way?</p>
  
  <p>-G</p>