Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I separate error handling from business logic in Perl?
    primarykey
    data
    text
    <p>How do I separate out exception handling / error handling from business logic? I'm writing code in Perl, and the error/exception handling and business logic makes it very difficult to understand code while reviewing.</p> <p>How can I refactor my code to make it more readable yet have error handling. Also note that I do not use try catch or anything like that.</p> <p>One of our senior programmers suggested that we re open OS standard error and write everything there and we can catch it by the caller.</p> <p>Edit : here is how I do the error handling . I have many Perl modules.. so <code>check2.pm</code> </p> <pre><code>package check2; sub printData { print STDERR "Error Message from sub routine \n"; } 1; </code></pre> <p>and i use it like so in my Perl script , <code>check.pl</code> </p> <p>In my Perl script </p> <pre><code>#!/usr/bin/perl use LoadModules; use strict; use warnings; load check2; my $stderrholder; local *SAVEERR; # First, save existing STDERR open SAVEERR, "&gt;&amp;STDERR" or print "not able to open"; close STDERR; # Open the STDERR to a variable open STDERR, "&gt;", \$stderrholder or die "Failed to reopen STDERR $!\n"; #Start of processing # Now print something to STDERR, redirected to $ stderrholder print STDERR " Error Message from Main script \n"; check2::printData(); #End of processing # Now close and restore STDERR to original condition. close STDERR; #open STDERR, "&gt;&amp;SAVEERR"; # Now check if there were any processing errors. if(length($stderrholder)) { print "\nProcessing errors\n" ; if(length($stderrholder)) { print "\nProcessing errors\n" ; print $stderrholder; } else { print "\nNo Processing errors\n" ; } </code></pre> <p>Would really appreciate if someone could help me point out errors in this.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload