Catch block does not work correctly for exceptions from get-spweb and get-spsite without the
-ErrorAction Stop parameter.
This code will not print "in catch block"
try{Get-SPWeb 'wrong url'} catch { Write-Host "in catch block" }
correct usage : try{Get-SPWeb 'wrong url' -ErrorAction Stop } catch { Write-Host "in catch block" }
-ErrorAction Stop parameter.
This code will not print "in catch block"
try{Get-SPWeb 'wrong url'} catch { Write-Host "in catch block" }
correct usage : try{Get-SPWeb 'wrong url' -ErrorAction Stop } catch { Write-Host "in catch block" }
Comments