Skip to content

Latest commit

 

History

History
55 lines (44 loc) · 714 Bytes

File metadata and controls

55 lines (44 loc) · 714 Bytes
description Avoid Using Empty Catch Block
ms.custom PSSA v1.21.0
ms.date 06/28/2023
ms.topic reference
title AvoidUsingEmptyCatchBlock

AvoidUsingEmptyCatchBlock

Severity Level: Warning

Description

Empty catch blocks are considered a poor design choice because any errors occurring in a try block cannot be handled.

How

Use Write-Error or throw statements within the catch block.

Example

Wrong

try
{
    1/0
}
catch [DivideByZeroException]
{
}

Correct

try
{
    1/0
}
catch [DivideByZeroException]
{
    Write-Error 'DivideByZeroException'
}

try
{
    1/0
}
catch [DivideByZeroException]
{
    throw 'DivideByZeroException'
}