To raise a specific exception, such as FileNotFoundException, use this format
if (-not (Test-Path $file)) { throw [System.IO.FileNotFoundException] "$file not found." }
To create a generic exception, use the throw command followed by a line.
throw "Error trying to do a task"
When used inside a catch, you can provide additional information about what caused the error
WiiBopp Jul 04 '14 at 23:05 2014-07-04 23:05
source share