Please feel free to provide feedback or file bugs here.

Terminating error in if statement script block generates duplicate errorvariable entries

Consider the following 2 functions (contrived to illustrate the issue).

function 1error { [CmdletBinding()] Param(); throw "This produces 1" }
function 2error { [CmdletBinding()] Param(); if($true) {throw "This produces 2"} }

If you call the function 1error with an error variable, the error variable will act as expected.

1error -ErrorVariable +1var
$1var.count #results in 1

If you call function 2error with an error variable, the error variable will have 2 identical errors.

2error -ErrorVariable +2var
$2var.count # results in 2

PSVersion is 5.1.14393.2189

4 votes
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    Signed in as (Sign out)

    We’ll send you updates on this idea

    Mike R. shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    0 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      Submitting...

      Feedback and Knowledge Base