How to separate exception handling / error handling from business logic? I write code in Perl, and error / exception handling and business logic make it very difficult to understand the code when viewing it.
How can I reorganize my code to make it more readable, but with error handling. Also note that I am not using try catch or anything like that.
One of our senior programmers suggested that we again open the standard OS error and write everything there, and we can catch it as the caller.
Edit: this is how I do error handling. I have many Perl modules. socheck2.pm
package check2;
sub printData {
print STDERR "Error Message from sub routine \n";
}
1;
and I use it like in my Perl script, check.pl
In my Perl script
use LoadModules;
use strict;
use warnings;
load check2;
my $stderrholder;
local *SAVEERR;
open SAVEERR, ">&STDERR" or print "not able to open";
close STDERR;
open STDERR, ">", \$stderrholder or die "Failed to reopen STDERR $!\n";
print STDERR " Error Message from Main script \n";
check2::printData();
close STDERR;
if(length($stderrholder)) {
print "\nProcessing errors\n" ;
if(length($stderrholder)) {
print "\nProcessing errors\n" ;
print $stderrholder;
} else {
print "\nNo Processing errors\n" ;
}
It would be very helpful if someone could help me point out errors in this.