Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Collapse the table of content
Expand the table of content
Expand Minimize

Converting VBScript's Raise Method

Windows PowerShell

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[0]) you’ll get back the following:

The file could not be found.

Return to the VBScript to Windows PowerShell home page

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft