[Python-bugs-list] [ python-Bugs-425261 ] re propagates opaque exceptions

noreply@sourceforge.net noreply@sourceforge.net
Tue, 22 May 2001 12:44:23 -0700


Bugs item #425261, was updated on 2001-05-18 10:53
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=425261&group_id=5470

Category: Regular Expressions
>Group: Not a Bug
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Fredrik Lundh (effbot)
Summary: re propagates opaque exceptions

Initial Comment:
If you call re.compile() with an erroneous expression,
the
underlying extension module (pcre, sre, ...?) raises an
exception which is propagated through re to the caller.

In order to catch the exception, it seems that you need
to
use an unqualified except clause, unless you import the
extension module, which is presumably supposed to be
opaque (particularly if its identity is variable!)

----------------------------------------------------------------------

>Comment By: Tim Peters (tim_one)
Date: 2001-05-22 12:44

Message:
Logged In: YES 
user_id=31435

/F forgot to close this -- closing it.

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2001-05-18 13:54

Message:
Logged In: YES 
user_id=31435

Sounds good to me!  Did you leave this open because you 
thought you were bluffing <wink>?


----------------------------------------------------------------------

Comment By: Nobody/Anonymous (nobody)
Date: 2001-05-18 13:43

Message:
Logged In: NO 

not a bug.

The "compile" method throws an "error" exception from
the *same* module, no matter what regular expression
module you're using.  This is how it's documented, and
this is how it works.

Or in other words, the following works, whether you've
used "import re", "import sre as re", or "import pre as
re":

   try:
      p = re.compile(...)
   except re.error:
      print "gotcha"

</F>

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2001-05-18 13:12

Message:
Logged In: YES 
user_id=31435

Assigned to /F.  Would probably be better if, e.g., 
sre_constants.error were a subclass of, say, SyntaxError?


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=425261&group_id=5470