PoshCode Logo PowerShell Code Repository

LibrarySqlBackup (modification of post by Chad Miller view diff)
diff | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1202"></script>download | new post

The trap statement for this script does not appear to function as suggested. When I try to run it and force an incorrect file location, it ignores the inner exception that would show the correct error.

  1. # ---------------------------------------------------------------------------
  2. ### From the Apress book "Pro Windows PowerShell" p. 164 I found the following trap handler that will get to the InnerException.Message
  3. # ---------------------------------------------------------------------------
  4. trap
  5. {
  6.     $exceptiontype = $_.Exception.gettype()
  7.     $InnerExceptionType = "no inner exception"
  8.     if($_.Exception.InnerException)
  9.     {
  10.         $InnerExceptionType = $_.Exception.InnerException.GetType()
  11.         # RV - Added following line to display message
  12.         $_.Exception.InnerException.Message
  13.     }
  14.  
  15.     "FullyQualifiedErrorID: $($_.FullyQualifiedErrorID)"
  16.     "Exception: $exceptionType"
  17.     "InnerException: $innerExceptionType"
  18.  
  19.     continue
  20. }

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me