title: Alternative to Throwing Param Exceptions in PowerShell?
body: <p><strong>Bottom Line Up Front</strong></p>
  
  <p>I'm looking for a method to validate powershell (v1) command line parameters without propagating exceptions back to the command line. </p>
  
  <p><strong>Details</strong></p>
  
  <p>I have a powershell script that currently uses <code>param</code> in conjunction with <code>[ValidateNotNullOrEmpty]</code> to validate command line paramaters:</p>
  
  <pre><code>param(
     [string]
     [ValidateNotNullOrEmpty()]$domain = $(throw "Domain (-d) param required.")
  )
  </code></pre>
  
  <p>We're changing the paradigm of error handling where we no longer want to pass exceptions back to the command line, but rather provide custom error messages. Since the <code>param</code> block can not be wrapped in a try catch block, i've resorted to something <em>like</em> the following:</p>
  
  <pre><code>param(
     [string]$domain = $("")
  )
  Try{
     if($domain -like $("")){
        throw "Domain (-d) param required."
      }
  ...
  
  }Catch{
  #output error message 
  }
  </code></pre>
  
  <p>My concern is that we're bypassing all of the built-in validation that is available with using <code>param</code>.  Is my new technique a reasonable solution?  Is there a better way to validate command line params while encapsulating exceptions within the script?  I'm very much interested in see how PowerShell professionals would handle this situation.  </p>
  
  <p>Any advice would be appreciated. </p>