Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function WriteError
  2. {
  3.     Write-Error "Error Occurred"
  4.  
  5.     "This still runs"
  6. }
  7.  
  8. function PSCmdletWriteError
  9. {
  10.     [CmdletBinding()]
  11.     param()
  12.  
  13.     $PSCmdlet.WriteError([System.Management.Automation.ErrorRecord]::new([System.Exception]::new("This is my Exception"), "ErrorID", [System.Management.Automation.ErrorCategory]::NotSpecified, "ObjectThatThrewException"))
  14.  
  15.     "this still runs"
  16. }
  17.  
  18. function TheThrow
  19. {
  20.     throw "I am throwing an exception"
  21.     "this does not run"
  22. }
  23.  
  24. function PSCmdletThrowTerminatingError
  25. {
  26.     [CmdletBinding()]
  27.     param()
  28.  
  29.     $PSCmdlet.ThrowTerminatingError([System.Management.Automation.ErrorRecord]::new([System.Exception]::new("This is my *TERMINATING* exception"), "My Error ID", [System.Management.Automation.ErrorCategory]::LimitsExceeded, "ObjectThatThrewException"))
  30.     "this doesn't run"
  31. }
  32.  
  33. WriteError
  34.  
  35. PSCmdletWriteError
  36.  
  37. PSCmdletThrowTerminatingError
  38.  
  39. TheThrow
  40.  
  41. "I don't run because a throw was used"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement