title: throwing more than one custom exception in powershell
body: <p>I have a situation where i have to throw multiple custom exceptions in a try block in my powershell script something like below</p>
  
  <pre><code>try {
      if (!$condition1) {
          throw [MyCustomException1] "Error1"
      }
      if (!$condition2) {
          throw [MyCustomException2] "Error2"
      }
  }catch [MyCustomException1] {
      #do some business logic
  }catch [MyCustomException2] {
      #do some other business logic
  }catch{
      #do something else
  }
  </code></pre>
  
  <p>Is there a way to do it in powershell without writing the .net class <code>MyCustomException1</code> and <code>MyCustomException2</code>. I don't have to store any info in the class but i just need a way to differentiate the exceptions. 
  I could do as below but i just wondering if something cleaner.</p>
  
  <pre><code>try {
      if (!$condition1) {
          throw "Error1"
      }
      if (!$condition2) {
          throw "Error2"
      }
  }catch {
      if($_.tostring() -eq "Error1"){
          Write-Host "first exception"
      }elseif($_.tostring() -eq "Error2"){
          Write-Host "Second exception"
      }else {
          Write-Host "third exception"
      }
  }
  </code></pre>
  
  <p>Note: I have already checked below stack overflow questions: <a href="https://stackoverflow.com/questions/11703180/powershell-creating-a-custom-exception">powershell-creating-a-custom-exception</a> <a href="https://stackoverflow.com/questions/2182666/powershell-2-0-try-catch-how-to-access-the-exception">powershell-2-0-try-catch-how-to-access-the-exception</a>  <a href="https://stackoverflow.com/questions/11981208/powershell-creating-and-throwing-new-exception">powershell-creating-and-throwing-new-exception</a>  But it doesn't answer my question.</p>