forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCatchOfGenericException.qhelp
More file actions
38 lines (32 loc) · 946 Bytes
/
Copy pathCatchOfGenericException.qhelp
File metadata and controls
38 lines (32 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<!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>