Skip to main content

Documentation Index

Fetch the complete documentation index at: https://tally.wharflab.com/llms.txt

Use this file to discover all available pages before exploring further.

powershell/PSAvoidUsingEmptyCatchBlock is a PSScriptAnalyzer diagnostic emitted by tally for PowerShell snippets embedded in Dockerfiles.
PropertyValue
SeverityWarning
CategoryPSScriptAnalyzer
Auto-fixNo

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.

Examples

Problematic code

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

Correct code

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

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

Source

This rule documentation is adapted from Microsoft’s PSScriptAnalyzer documentation for AvoidUsingEmptyCatchBlock, licensed under CC BY 4.0.