Converting VBScript's Raise Method
Definition: Generates a run-time error.
When testing scripts script writers need to ensure that their scripts can respond appropriately to specific errors. One way to do that is to simulate those errors programmatically. In VBScript this can be done using the Raise function; in Windows PowerShell this same thing can be done using the Throw method. In the following command an error message is assigned to the variable $b; the Throw method is then used to “throw” the error associated with $b:
$b = "The file could not be found."; throw $b
If you now check the value of the most recent error (that is, $error) you’ll get back the following:
The file could not be found.