Does re.compile() or any given Python library call throw an exception?
<p>I can't tell from the Python documentation whether the re.compile(x) function may throw an exception (assuming you pass in a string). I imagine there is something that could be considered an invalid regular expression. The larger question is, where do I go to find if a given Python library call may throw exception(s) and what those are? </p>

<p>Well, <code>re.compile</code> certainly may:</p>

<pre><code>&gt;&gt;&gt; import re
&gt;&gt;&gt; re.compile('he(lo')
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "C:\Python25\lib\re.py", line 180, in compile
    return _compile(pattern, flags)
  File "C:\Python25\lib\re.py", line 233, in _compile
    raise error, v # invalid expression
sre_constants.error: unbalanced parenthesis
</code></pre>

<p><a href="http://docs.python.org/lib/node46.html#l2h-408">The documentation</a> does support this, in a roundabout way - check the bottom of the "Module Contents" page for (brief) description of the <code>error</code> exception.</p>

<p>Unfortunately, I don't have any answer to the general question. I suppose the documentation for the various modules varies in quality and thoroughness. If there were particular modules you were interested in, you might be able to <a href="http://www.depython.net/">decompile</a> them (if written in Python) or even <a href="http://www.python.org/download/">look at the source</a>, if they're in the standard library.</p>
