http://qs321.pair.com?node_id=593262


in reply to Attempting to trap a DBI->connect error

By default DBI does not throw exceptions.
If you want it to you need to use the 4th argument to pass in a hashref telling it to do so like...
my $dbh = DBI->connect('db conn info here','userid','password',{RaiseE +rror => 1});
This will force DBI to throw errors with a die that you must catch with an eval.
This will also have the effect of making your code cleaner looking as you will not have to check for errors after every prepare, bind, execute, fetch... etc method you call. Just make sure you catch the errors.