Last active
July 1, 2019 15:41
-
-
Save chriskuech/54113f9f5740e1cd27fb0ee992c1776c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ErrorActionPreference = "Stop" | |
function Assert-True { | |
[CmdletBinding()] # add ErrorAction support | |
Param([boolean]$Value) | |
if (-not $Value) { | |
throw "Failed assertion" | |
} | |
} | |
# imperative error handling | |
try { | |
Assert-True $false | |
} catch { | |
Write-Host "nothing to see here..." | |
} | |
# equivalent functional error handling with Nullable monad | |
if (-not (Assert-True $false -ErrorAction SilentlyContinue)) { | |
Write-Host "nothing to see here..." | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment