When executing such a script:
nonexistingcommand
echo "Hello"
I get:
nonexistingcommand : The term 'nonexistingcommand' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the
name, or if a path was included, verify that the path is correct and try again.
At D:\Playground\powershell\Test.ps1:2 char:1
+ nonexistingcommand
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (nonexistingcommand:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Hello
So it seems that the CommandNotFoundException is a non-terminating error. So why if I
try {
nonexistingcommand
}
catch [System.Management.Automation.CommandNotFoundException] {
throw
}
echo "Hello"
In this case, it will exit and not print "Hello".
Why is that?