-
Notifications
You must be signed in to change notification settings - Fork 29
During Invoke-SqlUpdate, I want to catch an error about "Violation of UNIQUE KEY constraint" and handle it on my own. If any other error happens during Invoke-SqlUpdate, I want to let the default (whatever that is) occur.
I have tried every combination of
try {Invoke-SqlUpdate ... -ErrorAction Xyz}
catch {# Do something here}
But I can't ever reach the catch block. I can ignore this AND OTHER errors, or I can exit the function, etc. But I want to get into the catch block - at least for this one error.
(FWIW - I can easily get that error to occur in my code)
All reactions
Replies: 1 comment
@kwein123
-ErrorAction Stop should do what you want, it will stop the execution of the script, allowing the use of Try / Catch.
try { #this was run against a SQLite connection, the table does not exist and the syntax is incorrect... so an error is generated. Invoke-SqlUpdate "select top 10 from noexist" -ErrorAction Stop Write-Host "This should not be displayed!" } catch { # $_ is an error record... $_.exception }
All reactions
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment