mirror of
https://github.com/github/codeql.git
synced 2026-07-10 14:05:41 +02:00
39 lines
946 B
XML
39 lines
946 B
XML
<!DOCTYPE qhelp PUBLIC
|
|
"-//Semmle//qhelp//EN"
|
|
"qhelp.dtd">
|
|
<qhelp>
|
|
|
|
<overview>
|
|
<p>
|
|
Catching all exceptions with a generic catch clause may be overly broad. This can make
|
|
errors harder to diagnose when exceptions are caught unintentionally.
|
|
</p>
|
|
</overview>
|
|
|
|
<recommendation>
|
|
<p>
|
|
If possible, catch only specific exception types to avoid catching unintended exceptions.
|
|
</p>
|
|
</recommendation>
|
|
|
|
<example>
|
|
<p>
|
|
In the following example, a division by zero is incorrectly handled by catching all
|
|
exceptions.
|
|
</p>
|
|
<sample src="CatchOfGenericException.cs" />
|
|
|
|
<p>
|
|
In the corrected example, division by zero is correctly handled by only catching
|
|
appropriate <code>DivideByZeroException</code> exceptions. Moreover, arithmetic
|
|
overflow is now handled separately from division by zero by explicitly catching
|
|
<code>OverflowException</code> exceptions.
|
|
</p>
|
|
<sample src="CatchOfGenericExceptionFix.cs" />
|
|
</example>
|
|
|
|
<references>
|
|
</references>
|
|
|
|
</qhelp>
|