This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Must import sre_constants to catch re.compile errors.
Type: Stage:
Components: Regular Expressions Versions:
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: effbot Nosy List: effbot, jemfinch
Priority: normal Keywords:

Created on 2003-08-26 14:19 by jemfinch, last changed 2022-04-10 16:10 by admin. This issue is now closed.

Messages (3)
msg17954 - (view) Author: Jeremy Fincher (jemfinch) Date: 2003-08-26 14:19
It's a bit frustrating not to be able to catch 
exceptions raised by re.compile with just the re 
module.  The fact that sre_constants.error is 
raised is a bit too much implementation showing 
through, IMO. 
 
Anyway, I suggest a exception be added to the re 
module that subclasses sre_constants.error for 
backwards compatibility.  So users can simply 
import re and catch re.error instead of having to 
import re and sre_constants and catch 
sre_constants.error. 
msg17955 - (view) Author: Fredrik Lundh (effbot) * (Python committer) Date: 2003-08-26 16:47
Logged In: YES 
user_id=38376

afaik, the following has worked since 1.6, and still works 
in 2.3:

>>> import re
>>> try:
...     re.compile("[]*")
... except re.error:
...     print "oops"
...
oops

what Python version are you using?
msg17956 - (view) Author: Jeremy Fincher (jemfinch) Date: 2003-08-26 17:10
Logged In: YES 
user_id=99508

Oops, my fault. 
History
Date User Action Args
2022-04-10 16:10:50adminsetgithub: 39129
2003-08-26 14:19:27jemfinchcreate