This documentation is part of the BETA release and subject to change. |
Do not use trap statements |
Trap statements are designed for administrators. Try Catch should be used in all written script files. History: Trap was implemented in v1, because it was all the PowerShell team had time to implement.
CheckId | SPC019106 |
---|---|
TypeName | DoNotUseTrapStatement |
Severity | CriticalWarning |
Type | PoShFile |
Bad Practice
trap { ... }
Good Practicetry
{}
catch [ExceptionTypeException]
{
Write-Debug 'An ExceptionTypeException has occurred'
}
{}
catch [ExceptionTypeException]
{
Write-Debug 'An ExceptionTypeException has occurred'
}
Disclaimer: The views and opinions expressed in this documentation and in SPCAF do not necessarily reflect the opinions and recommendations of Microsoft or any member of Microsoft. SPCAF and RENCORE are registered trademarks of Rencore. All other trademarks, service marks, collective marks, copyrights, registered names, and marks used or cited by this documentation are the property of their respective owners.