title: How can I get around a 'die' call in a Perl library I can't modify?
body: <p>Yes, the problem is with a library I'm using, and no, I cannot modify it. I need a workaround.</p>
  
  <p>Basically, I'm dealing with a badly written Perl library, that exits with 'die' when a certain error condition is encountered reading a file. I call this routine from a program which is looping through thousands of files, a handful of which are bad. Bad files happen; I just want my routine to log an error and move on. </p>
  
  <p>IF I COULD modify the library, I would simply change the </p>
  
  <pre><code>die "error";
  </code></pre>
  
  <p>to a </p>
  
  <pre><code>print "error";return;
  </code></pre>
  
  <p>, but I cannot. Is there any way I can couch the routine so that the bad files won't crash the entire process?</p>
  
  <p>FOLLOWUP QUESTION: Using an "eval" to couch the crash-prone call works nicely, but how do I set up handling for catch-able errors within that framework? To describe: </p>
  
  <p>I have a subroutine that calls the library-which-crashes-sometimes many times. Rather than couch each call within this subroutine with an eval{}, I just allow it to die, and use an eval{} on the level that calls my subroutine:</p>
  
  <pre><code>my $status=eval{function($param);};
  unless($status){print $@; next;}; # print error and go to next file if function() fails
  </code></pre>
  
  <p>However, there are error conditions that I can and do catch in function(). What is the most proper/elegant way to design the error-catching in the subroutine and the calling routine so that I get the correct behavior for both caught and uncaught errors?</p>