<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>

[{'answer_id': 58129, 'author': 'Blair Conrad', 'author_id': 1199, 'author_profile': 'https://Stackoverflow.com/users/1199', 'pm_score': 5, 'selected': True, 'text': '<p>Well, <code>re.compile</code> certainly may:</p>\n\n<pre><code>&gt;&gt;&gt; import re\n&gt;&gt;&gt; re.compile(\'he(lo\')\nTraceback (most recent call last):\n  File "&lt;stdin&gt;", line 1, in &lt;module&gt;\n  File "C:\\Python25\\lib\\re.py", line 180, in compile\n    return _compile(pattern, flags)\n  File "C:\\Python25\\lib\\re.py", line 233, in _compile\n    raise error, v # invalid expression\nsre_constants.error: unbalanced parenthesis\n</code></pre>\n\n<p><a href="https://web.archive.org/web/20080913142948/http://docs.python.org/lib/node46.html" rel="nofollow noreferrer">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>\n\n<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="https://web.archive.org/web/20081004235506/http://www.depython.net/" rel="nofollow noreferrer">decompile</a> them (if written in Python) or even <a href="http://www.python.org/download/" rel="nofollow noreferrer">look at the source</a>, if they\'re in the standard library.</p>\n'}, {'answer_id': 58168, 'author': 'Matthew Schinckel', 'author_id': 188, 'author_profile': 'https://Stackoverflow.com/users/188', 'pm_score': 3, 'selected': False, 'text': '<p>Unlike Java, where there are exceptions that must be declared to be raised (and some that don\'t have to be, but that\'s another story), any Python code may raise any exception at any time.</p>\n\n<p>There are a list of <a href="https://docs.python.org/2.7/library/exceptions.html" rel="nofollow noreferrer">built-in exceptions</a>, which generally has some description of when these exceptions might be raised.  Its up to you as to how much exception handling you will do, and if you will handle stuff gracefully, or just fail with a traceback.</p>\n'}]
['https://Stackoverflow.com/questions/58119', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1892/']