|P is for Practical|
Re: $sth = $dbh->prepare($sql) or what?by blue_cowdawg (Monsignor)
|on Sep 21, 2012 at 13:49 UTC||Need Help??|
Me too! :-)
A recent consulting assignment I had had me refactoring legacy Perl code that was very heavily database access. Since the user interface to the application was a browser and PHBs were the target audience it was very undesirable to have raw error messages to be seen by the end user.
Further the requirement was to alert support staff depending on the severity of the error either by SMS or email. In any event all errors and warnings were to be logged with log rotation and retention.
So what's a Perl Monk to do?
There is nothing truly special about die that it can't be replaced by a home grown sub. Here is an example:
That's an oversimplified version of my error processing routine, but it will do for the purposes of this explanation. Each of the referenced subs:
Now to show execution examples:
The constant SEV1 was defined by a use constant invocation along with other severity levels. Since we are experiencing some form of connection issue to the database we want to halt further execution of the code. A severity 1 issue in my client's application was cause to not only alert the developers of an issue, but the DBAs and SysAdmins. (That's the logic I did not show in the sub above)
In this case we are going to send email to the developers letting them know a query failed. Since the end user has many ways to influence the query it might be a PEBKAC or it could be a real coding issue. Either way the developers need to know about it.
Stuff I didn't show (besides the priority logic in full) is the fact that I prepend all messages with __PACKAGE__ so the developers know where the prepare failed since there were about 50 home grown packages in play. I also when writing to the logs prepend the long version of the date and time of when the error was reported.
Hope this gives you some ideas on how to proceed.
Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg