title: Powershell catching exception type
body: <p>Is there a convenient way to catch types of exceptions and inner exceptions for try-catch purposes?</p>
  
  <p>Example code:</p>
  
  <pre><code>$a = 5
  $b = Read-Host "Enter number" 
  $c = $a / $b #error if $b -eq 0
  $d = get-content C:\I\Do\Not\Exist
  </code></pre>
  
  <p>Row #3 will generate a runtime error with an inner exception (EDIT: fixed this command $Error[1].Exception.InnerException.GetType()), row #4 will generate a "standard"(?) type of exception ($Error[0].Exception.GetType()).</p>
  
  <p>Is it possible to get the desired result from both of these with the same line of code?</p>
  
  <p>Ad1: error from row 3</p>
  
  <pre><code>At -path-:3 char:1
  
  + $c = $a / $b #error if $b -eq 0
  + ~~~~~~~~~~~~
      + CategoryInfo          : NotSpecified: (:) [], RuntimeException
      + FullyQualifiedErrorId : RuntimeException
  </code></pre>
  
  <p>Ad2: error from row 4</p>
  
  <pre><code>get-content : Cannot find path 'C:\I\Do\Not\Exist' because it does not exist.
  
  At -path-:4 char:6
  
  + $d = get-content C:\I\Do\Not\Exist
  
  +      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  
      + CategoryInfo          : ObjectNotFound: (C:\I\Do\Not\Exist:String) 
  [Get-Content], ItemNotFoundException    
      + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand
  </code></pre>
  
  <p>Edit: To make it clear, I want the result to return DivideByZeroException and ItemNotFoundException in some way</p>