-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathBreakOrReturnInFinally.qhelp
More file actions
32 lines (25 loc) · 1.1 KB
/
BreakOrReturnInFinally.qhelp
File metadata and controls
32 lines (25 loc) · 1.1 KB
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
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>When a <code>break</code> or <code>return</code> statement is used in a
<code>finally</code> block this causes the <code>try-finally</code> block
to exit immediately discarding the exception. This is unlikely to be the
intention of the developer and makes the code more difficult to read.</p>
</overview>
<recommendation>
<p>Either move the <code>break</code> or <code>return</code> statement to
immediately after the <code>finally</code> block or use an explicit
<code>except</code> block to handle the exception.</p>
<p>These modifications are behavior changing so you must take care to ensure
that the resulting behavior is correct.</p>
</recommendation>
<references>
<li>
Python Language Reference: <a href="http://docs.python.org/2.7/reference/compound_stmts.html#the-try-statement">
The try statement</a>, <a href="http://docs.python.org/2/reference/simple_stmts.html#break">
The break statement</a>, <a href="http://docs.python.org/2/reference/simple_stmts.html#return">
The return statement</a>.</li>
</references>
</qhelp>