I need to know how to customize my own errors in Perl. For instance, here's some code:
my $filename = 'filaname1.exe';
print "Copying $filename";
copy("$dir_root\\$filename", "$spcl_dir\\$filename");
if ($? == "0") {
print " - Success!\n";
}
else { print " - Failure!\n"; }
I tried to write this and "catch" the error and print "Failure" when I don't get an exit code of 0, and print "Success" when I do. I need to know how I can customize this; I don't really want to use die or anything like that where it will give a somewhat cryptic error (to the end user).
Thanks!
diegives mysterious and unintelligible messages, on your head be it, since you’re who’s passing the cryptic argument todie. You’ve no one else to blame.STDERR[2] includes$0, the name of the program that encountered the error as a minimum, and perhaps the function name; internal errors usually also give a stack trace [3] includes$!, the standard system error message wherever it’s appropriate, or perhaps$?or$@otherwise [4] states the name of the failed syscall [5] lists the arguments you gave that call. Your message neglects all, or nearly all, of those Five Rules for Good Error Messages.