Skip to main content

Understand how error messaging works

Error messages are often the key to understanding what went wrong with some code. It’s surprising how often people post questions that show output containing an error message, but don’t show effort to understand it.

Questions that don't show error messages, or demonstrate no effort to understand them will likely get downvoted and closed. Being able to read and understand error output is an essential skill to develop to become an effective programmer. No one will take time to fully explain this skill to you on Stack Overflow, so this is something you should learn and practice using other resources that teach programming. If you’ve already put in this effort and still don’t understand an error message, you should explain in the question what specifically you are confused about.

Learn how to read a stack trace

Many programming languages call the entire output of an unexpected error (or exception) a “stack trace” with each line of the output representing some line of code that was run just before the error happened. One line in particular will probably have an English description of the problem - this is what you want to pay extra attention to because it’s attempting to describe the problem.

If you don’t know how to read a stack trace, learn about that before posting to Stack Overflow. For example, if a Java stack trace doesn’t make sense to you, do a search for “how to read a java stack trace”. It is definitely your job as a programmer to understand how stack traces and error messaging works for the language you’re using.

The stack trace typically shows source code files and line numbers. You should always use this information to try to find the relevant code where the problem occurred, and include that code in your question. Be sure to indicate which line of code is the problem! The reader can’t see the line numbers in your editor, and they won’t want to try to count them on screen, so be clear about it. Make it as easy as possible for the reader to follow along with your exploration of the stack trace and find the lines that are most likely causing the problem.

Learn how to handle errors

You should also understand how best to capture and log errors. If you don't, you will get stuck on trivial problems, and your questions will likely get downvoted and closed.

If your code isn’t working at all, the first thing you should do is apply error checking to your code, capture the error message, and try your best to understand what it means. Without checking for errors, there is also a good chance that readers of your question will also not know what the problem is. In that case, you can expect comments asking for you to edit the question to show how you are handling errors, along with the contents of the error itself.

For example, if you’re working in JavaScript, and your code calls some function that returns a Promise, you should know how to use that Promise to capture any errors that happen as a result of a failure. You can do a web search for “javascript promise error handling” to learn about that, or consult the documentation for the framework you’re using, as it might have some special error handling conventions.