throw

noun

say it: “THROH” /θroʊ/

A PowerShell keyword that stops a script or function at once with an error showing a message you write.

What does throw do in PowerShell?

throw stops the script right there with an error, and the error's message is the text you give it. Use it when a script finds something it can't carry on without, such as a tool that isn't installed, so the person running it reads what to do instead of a confusing failure later.

if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
    throw 'Install git first: this project needs it.'
}

In a sentence

  • “When git was missing, the check task used throw to say Install git first.”
  • “A message given to throw should tell the reader what to do next.”

Level: Journeyman · More PowerShell terms at this level

Updated

In other subjects