<p>PyCharm向我展示了在到达return语句之前,在方法中有些代码是不可访问的。我不禁要问,这怎么可能呢?</p>
<pre><code>def post(self):
# get the desired parameters
username = self.request.get('user')
password = self.request.get('pass')
if not self.REGEX.match(username) or not self.REGEX.match(password):
logging.debug('RegistrationHandler: Bad credentials ->', username, password)
self.fail('bad username or password')
print 'Blah' # <---- shows as UNREACHABLE ?
return # <---- shows as UNREACHABLE ?
</code></pre>
<p><code>self.fail</code>只需调用<code>self.response.write(things)</code>。</p>
<p><strong>更新:</strong></p>
<p>是的,当我用try/catch子句包围它时,问题就解决了。。。很奇怪。(注意,该方法并不总是引发异常。</p>