Closed johlju closed 7 months ago
Maybe a Get-InvalidOperationException
that return an InvalidOperationException
would be better than a PassThru
parameter. New-InvalidOperationException
could re-use a Get-InvalidOperationException
, and New-ErrorRecord
(proposed in issue #99) could have an Exception
parameter that we could pass in with Get-InvalidOperationException
. 🤔
Get-*
suggest getting information that already exists somewhere, not creating new one. 🤔 Might be better to stick with New-*
and using -PassThru
that more suggest that we create something that will be returned on the pipeline.
Problem description
When using public commands we want to throw non-terminating errors using
Write-Error
, but also pass an exception or an error record to get the full stack trace.The command
New-InvalidOperationException
would make it easy to create a InvalidOPerationException if it wouldn't always throw.Verbose logs
How to reproduce
n/a
Expected behavior
New-InvalidOperationException
should be able to return the InvalidOperation exception object.Current behavior
ALways throws
Suggested solution
By adding a parameter
PassThru
it would return the exception object instead of throwing.We could then do:
We should also add a new
New-ErrorRecord
command (separate issue).Operating system the target node is running
PowerShell version and build the target node is running
Module version used