I heard a coworker talk about how he doesn't understand why some developers never seem to bother to actually try to comprehend an exception thrown in their (or other people's) code. And i never understood that either, but it has certainly bothered me in the past as well. So let's just list once and for all the steps a developer should follow when presented with a thrown exception.
- Check whether the exception has an inner exception. If not, proceed to step 2. If it does, check recursively until you've got the original exception (the one that doesn't have an inner exception).
- Read the exception message. Don't just glance at it, actually read it. If you got an 'aha!' moment upon reading it, you already know what to do. If you didn't, proceed to step 3.
- Take a look at the stacktrace. If the technology you're using prints its stacktraces in reverse chronological order (as in: the most recent method call is the first one listed) then open the first class of your code base that is listed in the stacktrace and go to the method of that class that is listed first in the stacktrace. If the stacktrace is printed in chronological order (as in: the most recent method call is the last one listed) then open the last class of your code base that is listed in the stacktrace and go to the method of that class that is listed last in the stacktrace. If line-numbers are displayed in the stacktrace, go the line-number that is printed next to the first mention of the first class of your codebase (in the case of reverse chronological order) or the last mention of the last class of your code base (in the case of chronological order) that is listed in the stacktrace. This is the part where you need to begin your search. The actual bug might be somewhere else, but at least you've got a starting point for your search. Once again, if you got an 'aha!' moment after this step, you already know what to do. If not, proceed to step 4.
- Here's where it gets tricky. Some people immediately enlist the assistence of a teammate at this point. Others spend hours searching until finally calling upon a teammate who might spot the problem after 10 seconds. If it's not immediately clear, spend 10 minutes tops looking for a solution before consulting with a teammate. If you haven't found a solution after 10 minutes, you haven't lost that much time and you can ask a teammate for help. If the teammate can help, neither of you lost a lot of time and at least you tried to fix it yourself before interrupting a teammate. If the teammate can't help, you're probably going to have to investigate this further on your own. Perhaps your teammate has enough time to help you, but don't count on it.
For a lot of the people reading this, there's absolutely nothing new in this list so i apologize for wasting your time. However, odds are high that you're going to run into a developer who can use this sooner or later so feel free to send him a link to this page ![]()
