Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Well error handling for your specific project will be just that, specific to your project. The scenerios you may or may not run into in this particular app will be most likely assosiated to the app therefore an error module probably would be a bad idea.

Write a module for a common task or event you plan on using across numerous projects and that would apply to numerous projects. In my opinion error handling does not fall into that category.

The main thing you should do with seeting up your logic flow for your project is handle ALL errors first in each situation. If you are envoking @ARGV at the command line then parse all command line args first and handle every possible error that could happen at command line (like typos or missing arguments) and then if all args pass then handle the obviously correct input (due to passing your error handling) accordingly.

Ex:

#!/usr/bin/perl -w use strict; # Error checking! die "Required argument missing!\n" unless ($#ARGV > 0); # This along with the following code ensures a positive numeric range. my $last = 0; # More Error handling! for (@ARGV) { # Ensures numeric input! die "Argument \"$_\" is not numeric!\n" unless (/\d+/); # Ensures a negative number was not entered as first argument and # also that the second argument is higher in value then the first. die "Invalid range!\n" unless ($_ > $last); $last = $_; } # Here we know that there was some sort of input at command line. # We also know that each argument is numeric. # We also know that the user gave a valid range in order for the app # to print out a consecutively increasing numeric count. # So with all the error handling passed if the program gets to this po +int. # we know we have the required VALID command line input in order for u +s to # successfully run this program. for ($ARGV[0] .. $ARGV[1]) { print; print"\n"; }
www.perlskripts.com

In reply to Re: How to handle Errors? by Elijah
in thread How to handle Errors? by Scarborough

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? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2023-02-05 14:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (31 votes). Check out past polls.

    Notices?