Boost logo

Boost :

From: Joe Gottman (jgottman_at_[hidden])
Date: 2006-04-03 20:03:35

"Anne Martens" <mail_at_[hidden]> wrote in message
> Hi,
> I'm trying to use boost-regex in my project that doesn't support
> exceptions. Thus, when constructing a regular expression with
> boost::regex expression(expr); and passig an invalid regular expression,
> my program crashes.
> What can I do to make sure my regular expression is valid before passing
> it to exception-throwing methods like that one?

   One possibility is to use a try-catch inside your function that produces
the regex, and return optional<regex>

optional<regex> maybe_make_regex(const string &s)
    try {
        return regex(s);
    } catch (...) {
        return none;

Joe Gottman

Boost list run by bdawes at, gregod at, cpdaniel at, john at