in reply to
DBI fails to return an error code
Are you by any chance the same person that posted on stackoverflow at http://stackoverflow.com/questions/7432944/undefined-dbierrstr-using-dbi-perl-and-mysql-on-windows-7-x64/7434259 and who posted to dbi-users mailing list at http://email@example.com/msg34081.html and reported https://rt.cpan.org/Public/Bug/Display.html?id=71047?
If so I have tried to help on some of those forums but you need to come up with something demonstrable that anyone else can run. The problem is that every pseudocode version you've posted works fine for me so I can only assume a) you have different versions or b) I've misinterpreted your pseudocode.
Write a small self contained real example that fails, post it along with your Perl, DBD::mysql and DBI versions and show the exact output of the script which demonstrates $DBI::errstr is not defined. Then if we cannot reproduce it we can help you debug it or perhaps trace it but we need to see a real life full example.