Export (0) Print
Expand All
Expand Minimize
0 out of 1 rated this helpful - Rate this topic

Converting VBScript's Raise Method


Windows PowerShell


Definition: Generates a run-time error.

Raise

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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.