PoshCode Archive  Artifact [aee2edef9f]

Artifact aee2edef9f60291d3fffc99bc03928477bcb1c2129b3c2dfe7627bc6ce15d84c:

  • File LibrarySqlBackup.ps1 — part of check-in [9366a70dbc] at 2018-06-10 12:56:38 on branch trunk — 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. (user: Chad Miller size: 1212)

# encoding: ascii
# api: powershell
# title: LibrarySqlBackup
# description: 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.
# version: 0.1
# author: Chad Miller
# license: CC0
# x-poshcode-id: 1202
# x-archived: 2015-01-07T23:52:09
# x-published: 2010-07-07T14:56:00
#
#
# ---------------------------------------------------------------------------
### From the Apress book "Pro Windows PowerShell" p. 164 I found the following trap handler that will get to the InnerException.Message
# ---------------------------------------------------------------------------
trap
{
    $exceptiontype = $_.Exception.gettype()
    $InnerExceptionType = "no inner exception"
    if($_.Exception.InnerException)
    {
        $InnerExceptionType = $_.Exception.InnerException.GetType()
        # RV - Added following line to display message
        $_.Exception.InnerException.Message
    }

    "FullyQualifiedErrorID: $($_.FullyQualifiedErrorID)"
    "Exception: $exceptionType"
    "InnerException: $innerExceptionType"

    continue
}