PowerShell v5. Windows 7 Pro.
When I run this function from the console it gives the expected results. As it does
when placed inside a module. However, if I remove the Set-StrictMode -Version 1 line
the module version fails to catch any error and always gives the result 'Off' regardless of the
local StrictMode setting, be it either 1 or 2. I am missing something very simple here
This is what normally happens in the script; but load the above code into a module (omitting any Set-StrictMode lines), then Import-Module c:\modules\testModule, locally Set-StrictMode -Version 2, run Get-Test. Always returns 'Off', as the catch block is bypassed. I would like to know why; and how to import the StrictMode value into the module scope.
The topic ‘Set-StrictMode affecting try/catch inside module.’ is closed to new replies.