Perl: catch error without die
        Posted  
        
            by Pmarcoen
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Pmarcoen
        
        
        
        Published on 2010-04-13T09:41:24Z
        Indexed on 
            2010/04/13
            9:42 UTC
        
        
        Read the original article
        Hit count: 452
        
I'm playing around with error handling and got a little problem. I connect with a database using the DBI module.
I do my own error handling by using a subroutine that I call upon an error.
I can catch my own dies and handle them just fine but when my database connection fails, the DBI module apparently prints out it's own die :
DBI connect(...) failed: ORA-12154: TNS:could not resolve the connect identifier specified (DBD ERROR: OCIServerAttach) at ...
How would I go about catching this ?
I tried using $SIG{DIE} like so :
local $SIG{__DIE__} = sub {
  my $e = shift;
  print "Error: " .$e;
};
This is on the bottom of my main file, in this file I also call the connect subroutine that is available in a module of my own. I also tried putting this piece of code on the bottom of my module but it still prints the error without the "Error:" in front of it.
© Stack Overflow or respective owner