title: How to capture exception thrown by gem install in powershell
body: <p>I'm trying to capture the exception thrown while installing gems, I see the error on the command window however I'm not able to capture the error in catch block, I would like to capture and log in logs file, below is the code.</p>
  <pre><code>try{
  
      $tiny= .\gem install --local c:\mypath\tiny_tds-2.1.5-x64-mingw321.gem
      
      if($tiny -eq $null){
          throw
      }
      Write-Host &quot;Installation completed  :&quot; $tiny
  }
  catch{
  $string_err = $_ | Out-String
  Write-Host &quot;*****************************&quot;
  Write-Host $string_err
  Write-Host &quot;*****************************&quot;
  }
  </code></pre>
  <p>Error that I get on powershell command window</p>
  <p><a href="https://i.stack.imgur.com/vycjt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vycjt.png" alt="enter image description here" /></a></p>