140 likes | 364 Views
Eclipse Tip – Debugging in Eclipse. Using the Debugger in Eclipse to Find and Fix Run-Time Errors. Run-time and Logic Errors. Eclipse provides help in correcting errors at compile-time through messages, tooltips, and other approaches
E N D
Eclipse Tip – Debugging in Eclipse Using the Debugger in Eclipse to Find and Fix Run-Time Errors
Run-time and Logic Errors • Eclipse provides help in correcting errors at compile-time through messages, tooltips, and other approaches • This presentation focuses on the other common types of errors: run-time errors • Program exceptions (crashes) • Logic errors: the program runs but produces incorrect results
The Debugger in Eclipse • Often, the causesof logic errors and even program crashes can be determined by “watching the program run” one line at a time • Step through the program by executing one line at a time and watch the results of each line as it executes • When something unexpected happens, we have identified a segment of the program that requires additional attention
The Debugger in Eclipse • The Debugger in Eclipse allows us to execute parts of a program at full speed, pause on certain lines (called breakpoints), and execute subsequent code one line at a time • When paused at a breakpoint or executing one line at a time, the debugger allows us to inspect the current values of variables, arrays, ArrayLists, and so forth in scope at the moment • This is a “snapshot” at that point in the program
Setting a Breakpoint • Select a line of executable code where you want the program to pause • Double-click in the left-margin of the editor to set a breakpoint Blue ball indicates a breakpoint on this line
Breakpoints • You may set as many breakpoints as you wish • Breakpoints can only be set on lines that are executable (not comments, blank lines, etc.) • Breakpoints can be toggledoff by double-clicking on the blue ball • Breakpoints have no effect when executing the program normally • Executionpauses at every breakpoint when in “debuggingmode”
Debugging Perspective • Normally, when editing and testing a program, Eclipse is in the Java Perspective and looks as you have come to expect • When debugging, the appearance of Eclipse changes to the DebugPerspective • One can go back to the normal JavaPerspective by clicking the Javabutton in the upper right corner of the Eclipsewindow
Now in Debug Perspective Click this button to run the program in “Debug Mode” Return to Java Perspective Values of relevant variables shown here Execution paused here
Step over Step into Hover mouse over variable to see its value Tooltip with value