The Community Book of Powershell Practices Master by Powershell.org - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

21. ERR-03 Avoid using flags to handle errors

Try to avoid setting flags:

““

Try {

$continue = $true

Do-Something -ErrorAction Stop

} Catch {

$continue = $false

}

if ($continue) {

Do-This

Set-That

Get-Those

}

Instead, put the entire "transaction" into the Try block:

Try {

Do-Something -ErrorAction Stop

Do-This

Set-That

Get-Those

} Catch {

Handle-Error

}

““

It’s a lot easier to follow the logic.

 

Find Your Next Great Read

Describe what you're looking for in as much detail as you'd like.
Our AI reads your request and finds the best matching books for you.

Showing results for ""

Popular searches:

Romance Mystery & Thriller Self-Help Sci-Fi Business