Exceptions and errors are good, not evil (interlude)

Posted: February 17, 2016 in Programming

I remember that when I started to work as programmer/developer, I hated exceptions and errors. I thought that, in that point of time, everything is better than having your application run into exception message with some nasty error screen.

Today, development goal is the same, application should work flawlessly, as per design, without appearance of any error screen.

However, difference is technology advancement nowadays as well as in my maturity as a developer and acceptance of the fact that exceptions and errors have key role in achievement of application quality and development productivity. Today I appreciate exceptions and errors, I almost get excited when I see one.

Let’s go back in time when geeks were not ruling the world

In order to understand why exceptions were most hated you would have to travel trough time, at least 15 years back to see and feel level of technology development in those days, when, per example, you only had Internet Explorer and Netscape Navigator as a browsers available, with none of decent debugging support from any of mentioned.

Writing Javascript and tuning up CSS was near to hell. It was mostly based on try-test approach, while errors in Javascript were so unreadable and fuzzy that debugging Javascript was one of the most stressful tasks ever.

Backend/application development was little less stressful, most of the time you had debugger available, depending on language and tools which you were using. In my 15+ years of development, I have worked with Java, Javascript, C#, ASP, PHP, VB as well as a lot of meta-languages and DBMS – and I remember that most  common error messages you could stumble upon was something like “Error 20023 – bad flag at pointer x867580“.

If you had debugger, you could go trough application execution stack and see what is wrong. If you worked on javascript in IE4 or 5, you were literally sc***ed, you would get some unrelated error message pointing to wrong line of code.

So, having something so explanatory makes no wonder why we hated exceptions and errors.

PHP, as my major language, had implementation of worst error messages ever. I had rule in those days which worked most of the time, and it was “If error message says that A is a problem, 90% of the chance it is actually something completely different.

New era of clear error messages begun

But everything changed dramatically fast, in couple of years only. Developers started to dedicate more attention to error messages. They finally realised that developers do hate debugging and that debugging takes to much time in development process.

On my faculty, during my formal education, I have stumbled upon information in conventional literature that debugging takes more than 50% of development time. In that point of time, that was really true, productivity was really low, we were missing sophisticated software tools, bad-ass hardware, and on top of that, we had very fuzzy error messaging supporting error handling.

And – boom! One day, I started my application and got: “RuntimeException on line X in class X: ‘cache_dir’ is not writeable.“. I changed perms of cache dir, and everything worked! That approach of error messages changed everything! Message clearly stated what was really wrong. New era of errors and exceptions begun.

Soon enough – we all implemented this practice, we were pointing exactly what was the error and how to fix it. If you do your PHP development, per example, in Symfony, I guess you stumbled on some of the error messages where reason for error is not clear enough in runtime, but author of library that throwed exception stated all known possible reasons just to help you to identify and fix the error.

How often do you use debugger actually?

I can not remember when was the last time I have turned on debugger, honestly. Error messages are getting so clear and comprehensive now, that most of the time you can identify errors trough exception messages.

Of course, there are some minor “dirty debugging” practices when it comes to PHP and environment which includes xdebug:


which I do not recommend nor promote, but I use often 🙂 with 99.99% of success rate in finding error in matter of seconds.

Debuggerless debugging

I believe that we are now entering the era of “debuggerless debugging” – just because authors of vendor libraries do their best to help us understand what went wrong.

Soon enough, errors and exceptions were not just the problem in application, they were part of the solution. Nowadays we are hoping to taunt them as soon as possible, all of them, so we can ensure application quality. And more and more, we throw exceptions whenever we find suitable, providing as much info about it as possible.

Hence, my team and I have certain coding standards and practices in throwing exceptions which we follow when we code.







Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s