Developing and debugging your web applications on your local environment is pretty straightforward, but things get more hectic when shit hits the fan for a user on a live server. If something went wrong, will the user bother to tell you? will he give sufficient information and would be willing to follow up until the issue is resolved? or more likely he will leave your site and you will be none the wiser.
How can we catch errors and have enough information to debug them without relying on the kindness of users?
Step 1. Real-time notifications
Our first step in catching errors is to receive notifications when they happen. Most errors do get logged to the error log, but most likely they will go unnoticed for a period of time until someone decides to check the logs.
There are a few ways to get notified of errors, the most common include Emails and text messages (SMS), as well as peer to peer text messaging. I usually go the Email approach, and have the server send me an Email whenever an error above a certain severity occurs.
(The following code is in PHP, but the concepts can be applied to your language of choice)
In PHP we have two methods to catch errors – a custom error handler and the register_shutdown_function() function which handles fatal errors that kill the script before the custom error handler can be applied.
To know when the next article is published, please subscribe to new articles using your Email below or follow me on Twitter.