Skip to content

Thrown Error handled differently between PowerShell 7 and PowerShell 5 #2355

Answered by fflaten
JamSpot asked this question in Q&A
Discussion options

You must be logged in to vote

I don't think Pester is relevant here. PowerShell is unable to find the type, so it can't execute your try/catch statement at all regardless of which clause it should match.

Ex. run this directly:

try {
  throw 'omg'
} catch [Azure.Identity.AuthenticationFailedException] {
  write-warning "I don't exist"
} catch {
  write-host 'caught omg!' -foregroundcolor green
}

# my output

InvalidOperation:
Line |
   3 |  } catch [Azure.Identity.AuthenticationFailedException] {
     |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Unable to find type [Azure.Identity.AuthenticationFailedException].

As mentioned, ALC is only available in PowerShell 7+, so when you use the same modules …

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@JamSpot
Comment options

@fflaten
Comment options

Answer selected by JamSpot
@JamSpot
Comment options

@fflaten
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants