Asserting on the expected message in the exception is nice:
{ throw 'foo' } | Should Throw 'foo'
But what if I wanted to examine additional properties of the exception, or even the exception type? I'm forced to do this:
$caughtException = $null
try {
throw (new-object system.notimplementedexception)
} catch {
$caughtException = $_
}
$caughtException | Should Not Be $null
$caughtException.Exception.GetType() | Should Be ([System.NotImplementedException])
$caughtException.Exception.Message | Should ...
$caughtException.Exception.CustomProperty | Should ...
Proposed Syntax
$action = { throw (new-object system.notimplementedexception) }
$actualException = $action | Should Throw ([System.NotImplementedException]) "My Message" -PassThru
$actualException.CustomProperty | Should ...
Asserting on the expected message in the exception is nice:
{ throw 'foo' } | Should Throw 'foo'But what if I wanted to examine additional properties of the exception, or even the exception type? I'm forced to do this:
Proposed Syntax