Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
the unreliable part is writing good regular expressions which are not fragile in the face of simple changes to unstructured data

Ah! Now we're getting some where. I'm going to assume that you don;t consider yourself incapable of writing a good regex; which by implication suggests that you assume that wonderful catch-all, "other people", can't.

There's a really simple solution to that: regularise your error messages.

You're already advocating moving your exceptions into a single file--the Exception::Class using exception declaration module.

So, do the same thing with your error messages. And make them easy to parse:

package MyModule::Errors; use constant { ERROR001 => 'MyModule::Error001: The frobwitz has a %d chance of r +eaching critcial mass", ERROR002 => 'MyModule::Error002: The doobry '%s' is frazzled', ... }; 1;

Now all you need is:

eval { somefunc() ); if( $@ =~ m[^MyModule::Error002] ) { ... };

Simple. Lightweight. Reliable.

Of course, now we're well on the way to returning error numbers instead of strings. And then providing a function (class method) that converts them to an error text (when required). With the added benefit of making I8N simple.

Don't cover up simple design issues by layering heavy & complicated code over the top. Design a solution that addresses those issues at source. In this case, the source is the string form of the error returns, not the regexes the user needs to use to handle them.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^11: eval to replace die? by BrowserUk
in thread eval to replace die? by hsmyers

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-23 15:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found