DebuggingAndExceptions

DebuggingAndExceptions - CSE 219 Computer Science III...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSE 219 Computer Science III Debugging & Exceptions Testing vs. Debugging Testing tells us that something is wrong with a program Doesnt tell us how to fix it Once we know a problem exists we debug Debugging The process of understanding and correcting errors First locate the problem Find line of your code that produces initial problem Then address the algorithm Correct implementation of algorithm or algorithm itself Debugging Important skill for proficient programmer Reveal bugs that are not otherwise evident (like infinite loop) But, dont design to debug Dont rely on debugging to write your code Try to define and implement correct algorithms Even a fast debugging process is slow relative to implementing an algorithm correctly the first time Good debugging strategy when you know a bug exists for a particular case 1. Determine in which class the error (ex: exception) originates, then: 2. Determine in which method the error originates, then: 3. Determine on which line of code the error originates Knowing where the problem originates is half the battle Common Bugs Revealed by Debugging Un-constructed Objects Un-initialized Variables Improper Iteration Missing Implementations Incomplete changes made to a program Failing to reinitialize a variable the second time through a program segment NOTE: as expected, sources of logical errors are much more difficult to detect than those of runtime errors Planning for Debugging Assumption: every program will contain faults no programmer gets it right the first time Design, write, & document your programs in ways that will make them easier to test & debug A professional programmer may keep a log (diary) of his or her programming bugs for reference in future debugging tasks. We tend to make the same mistakes over and over again. Debugging by Brute Force Scatter print statements randomly throughout the program Displays the contents of selected variables Facilitates the study of the programs dynamics Advantage: Very easy to implement Disadvantage: Can affect the readability of the program code Can be a hit-or-miss approach Not easy to use for large-scale programs Can produce large volumes of data Can not identify certain types of problems Debugging by Brute Force Example...
View Full Document

This note was uploaded on 05/10/2008 for the course CSE 219 taught by Professor Mckenna during the Spring '08 term at SUNY Stony Brook.

Page1 / 24

DebuggingAndExceptions - CSE 219 Computer Science III...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online