Debugging finding errors
There are several things you can do to find errors and fix them.
This tutorial focuses on:
- Get the line number
- Get the error message
- Code in the address bar
- Setting breakpoints
Get the line number
When an error occurs some browsers will tell you the line number that the error occurred on. This is a very practical thing that saves you the effort of looking through multiple lines of code to find the error.
This PHP code will get a web browser to display a report (instead of a webpage) that the error occurred on line 5.
Get the error message
Some browsers will tell you in detail what the error is.
- alrt is not defined on line 3
- unterminated string literal on line 4
The above PHP code will get a web browser to display a report (instead of a webpage) saying Parse error: parse error, expecting `','' or `';'' on line 5
Code in the address bar
Use this technique to do things like display the value of a variable or the text within a textbox which will help you in your quest to fix errors on the page.
NOTE: This technique can be done in all the major browsers - Firefox, Internet Explorer, Opera, Chrome, and Safari.
A breakpoint is a place in code where execution is purposely stopped. A breakpoint is set to test the code for certain things and see how it functions up to a certain point. You can set breakpoints using some of the tools we discuss in the Debugging tools page.
You don't always have to look for errors manually, there are many tools that will help you do it.
Our Debugging tools page contains a full list of debugging tools you can use as well as instructions on how to use each one.