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'
}
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for