description | ms.custom | ms.date | ms.topic | title |
---|---|---|---|---|
Avoid Using Empty Catch Block |
PSSA v1.22.0 |
06/28/2023 |
reference |
AvoidUsingEmptyCatchBlock |
Severity Level: Warning
Empty catch blocks are considered a poor design choice because any errors occurring in a
try
block cannot be handled.
Use Write-Error
or throw
statements within the catch block.
try
{
1/0
}
catch [DivideByZeroException]
{
}
try
{
1/0
}
catch [DivideByZeroException]
{
Write-Error 'DivideByZeroException'
}
try
{
1/0
}
catch [DivideByZeroException]
{
throw 'DivideByZeroException'
}