-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
373 additions
and
63 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<# | ||
.SYNOPSIS | ||
Creates and returns an exception. | ||
.DESCRIPTION | ||
Creates an exception that will be returned. | ||
.OUTPUTS | ||
None | ||
.PARAMETER Message | ||
The message explaining why this error is being thrown. | ||
.PARAMETER ErrorRecord | ||
The error record containing the exception that is causing this terminating error. | ||
.OUTPUTS | ||
System.Exception | ||
.EXAMPLE | ||
$errorRecord = New-Exception -Message 'An error occurred' | ||
Creates and returns an exception with the message 'An error occurred'. | ||
.EXAMPLE | ||
try | ||
{ | ||
Get-ChildItem -Path $path -ErrorAction 'Stop' | ||
} | ||
catch | ||
{ | ||
$exception = New-Exception -Message 'Could not get files' -ErrorRecord $_ | ||
} | ||
Returns an exception with the message 'Could not get files' and includes | ||
the exception that caused this terminating error. | ||
#> | ||
function New-Exception | ||
{ | ||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')] | ||
[CmdletBinding()] | ||
[OutputType([System.Exception])] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[System.String] | ||
$Message, | ||
|
||
[Parameter()] | ||
[ValidateNotNull()] | ||
[System.Management.Automation.ErrorRecord] | ||
$ErrorRecord | ||
) | ||
|
||
if ($null -eq $ErrorRecord) | ||
{ | ||
$exception = New-Object -TypeName 'System.Exception' ` | ||
-ArgumentList @($Message) | ||
} | ||
else | ||
{ | ||
$exception = New-Object -TypeName 'System.Exception' ` | ||
-ArgumentList @($Message, $ErrorRecord.Exception) | ||
} | ||
|
||
return $exception | ||
} |
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
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
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
Oops, something went wrong.