PowerShell has two types of errors:
Terminating errors
Non-terminating errors
By default, terminating errors will be written to the error stream and force a script to end immediately, whereas (again, by default), non-terminating errors will be written to the same error stream but allow the script to continue with its execution.
Most cmdlets generate non-terminating errors. The reason for this is simple. If I have the following command:
Get-Content file.txt | Get-Service
And someone remembers to write the 'helloWorld' on the very first line of that file, it will try to search for a service called 'helloWorld' and throw an error. Should this fail the whole script? Probably not. It should output a single error saying it failed
on this service and continue to the next one. Imagine I wanted to do more meaningful things, like delete files, remove directories, etc.
If I have a list of files to delete and it fails on a single file, by default it will attempt to do the remaining ones.
This is the purpose of non-terminating errors.
If you have something that you REALLY must ensure is in a very particular state before continuing (you can't carry the next instruction unless you've confirmed a file is deleted for example), then you can force it to issue a terminating error, as such:
Remove-Item c:\windows\system32\format.com -ErrorAction Stop
If I run this from a non-elevated powershell window it will fail as I don't have permissions, but also stop the whole script from running.
Try..catch can't catch non-terminating errors, but if you put an -ErrorAction Stop at the end of the cmdlet you're trying to run, it will be 'transformed' into a terminating error and you can catch then catch it.
What you're trying to do will define what the best way to do it is. Rather than giving examples post your code so we can have a look at exactly what you're trying to do and find a way of giving you what you want.