2,187
edits
m (Added "Exceptions and Error Handling") |
m (→Exceptions and Error Handling: Added basic info) |
||
Line 204: | Line 204: | ||
== Exceptions and Error Handling == | == Exceptions and Error Handling == | ||
* http://huddledmasses.org/trap-exception-in-powershell/ | |||
To control how a script behaves as a result of an exception, modify the <code> $ErrorActionPreference </code> variable, if required. | |||
{|cellpadding="1" cellspacing="0" border="1" | |||
|- style="background-color:#bbddff;" | |||
! Value !! Effect | |||
|- | |||
| Continue || [Default] Outputs error, but keeps processing | |||
|- | |||
| SilentlyContinue || No output and it keeps going | |||
|- | |||
| Inquire || Prompt user for action | |||
|- | |||
| Stop || Outputs error and halts processing | |||
|} | |||
=== Basic Error Catcher === | |||
If you know where the error is likely to occur, then just place an error catcher immediately after it... | If you know where the error is likely to occur, then just place an error catcher immediately after it... | ||
Line 212: | Line 229: | ||
# Handle error here | # Handle error here | ||
} | } | ||
</pre> | |||
[[Category:PowerShell]] | [[Category:PowerShell]] | ||
[[Category:WMI]] | [[Category:WMI]] | ||
[[Category:MySQL]] | [[Category:MySQL]] |