in reply to Re: Catching expressions from a file
in thread Catching expressions from a file
open my $fIn1, '<', $filename or die "Failed to open '$filename': $!\n +";
is much, much better than the two parameter version of open. If the OP really does want to fail silently then replacing the die with a return as you suggest is fine. Much better though is to leave the die there and have the calling code be explicit about error handling by wrapping the call in an eval and explicitly ignore expected failure modes:
eval { Grab($filename); return 1; } or do { my $err = $@; return if $err =~ /File not found/; die $err; };
which gives good information about unexpected error modes and makes it clear that missing files are expected and unimportant (such failures are ignored).
If you ignore error handling the errors will still happen and manifest themselves in some fashion. But most likely the way they manifest will not be at all obviously related to the underlying error. Spending a little time adding error handling up front almost always pays for itself. Even without writing any code, thinking about failure modes will head off many bugs before they get the chance to bite.
|
|---|