Skip to content

Latest commit

 

History

History

Errors-of-unusual-type

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Errors of unusual type

According to the documentation, there are two types of PowerShell errors, terminating and non-terminating.

There is yet another obscure third type of errors. Such errors are caught by try and trap, i.e. they behave like terminating, but they do not stop execution without try or trap, i.e. they behave like non-terminating.

For example, if a command name is not recognized as the name of a cmdlet, function, script file, or operable program then PowerShell emits an error. Is this error terminating or not? It depends. By default it is not, surprisingly.

It looks like constant use of either error action preference Stop or try or trap blocks in scripts is a good idea. Otherwise semi-terminating errors may cause problems because invocation continues. Note that the default error action preference is Continue.

Examples of semi-terminating errors:

  1. A command is not found.
  2. Division by zero.
  3. Calling .NET methods with wrong arguments.
  4. PowerShell cannot convert data to some type.
  5. A .NET type is not found.
  6. A property is not found in the strict mode.
  7. A variable is not found in the strict mode.
  8. A command parameter is not found.
  9. Assignment to not writable variables.
  10. Not supported provider features.
  11. A .NET exception.

Hypothesis

The tests give the idea that any runtime exception is a semi-terminating error.

In scripts, somewhat reliable terminating errors are caused by throw. But even throw may not terminate in some practically rare cases, see Throw-may-not-terminate.

Scripts