Error Analysis Logic Errors.

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Advertisements

COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
Debugging Introduction to Computing Science and Programming I.
General Computer Science for Engineers CISC 106 Lecture 21 Dr. John Cavazos Computer and Information Sciences 04/10/2009.
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
How to Debug VB .NET Code.
CIT 590 Debugging. Find a laptop Please take a moment to open up your laptop and open up Eclipse. If you do not have a laptop, please find a friend. If.
Using a Debugger. SWC What is ”debugging”? An error in a computer program is often called a ”bug”… …so, to ”debug” is to find and get rid of errors in.
DEBUGGING CHAPTER Topics  Getting Started with Debugging  Types of Bugs –Compile-Time Bugs –Bugs Attaching Scripts –Runtime Errors  Stepping.
Program Development Life Cycle (PDLC)
Debugging in Java. Common Bugs Compilation or syntactical errors are the first that you will encounter and the easiest to debug They are usually the result.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
ME 142 Engineering Computation I Debugging Techniques.
Testing and Debugging Session 9 LBSC 790 / INFM 718B Building the Human-Computer Interface.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Debugging Visual Basic.NET Programs ► ► Use debugging tools ► ► Set breakpoints and correct mistakes. ► ► Use a Watch and Local window to examine variables.
1 Original Source : and Problem and Problem Solving.ppt.
Debuggers in Python. The Debugger Every programming IDE has a tool called a debugger. This application does NOT locate or fix your bugs for you! It slows.
Copyright © 2004 – 2013 Curt Hill Java Debugging In Eclipse.
11 Debugging Programs Session Session Overview  Create and test a method to calculate percentages  Discover how to use Microsoft Visual Studio.
Debug in Visual Studio Windows Development Fundamentals LESSON 2.5A.
Debugging What coders (programmers) do to find the errors (“bugs”) in their own programs “Bugs” – Admiral Grace Hopper, developer of the world’s first.
Using the Eclipse Debugger Extra Help Session (Christina Aiello)
Chapter 2 Wrap Up 2/18/16 & 2/22/16. Topics Review for Exam I DecimalFormat More Style Conventions Debugging using eclipse The Java API.
Debuggers. Errors in Computer Code Errors in computer programs are commonly known as bugs. Three types of errors in computer programs –Syntax errors –Runtime.
11 Making Decisions in a Program Session 2.3. Session Overview  Introduce the idea of an algorithm  Show how a program can make logical decisions based.
Structured Programming The Basics
FOP: While Loops.
FOP: Multi-Screen Apps
Debugging with Eclipse
CMPT 120 Topic: Python’s building blocks -> More Statements
ME 142 Engineering Computation I
BIT116: Scripting Lecture 06
FOP: Buttons and Events
INTERMEDIATE PROGRAMMING USING JAVA
What to do when a test fails
Putting Objects in Motion
Eclipse Navigation & Usage.
Testing and Debugging.
Computer Programming I
Software Design and Development
Debugging CMSC 202.
Testing Key Revision Points.
Barb Ericson Georgia Institute of Technology Dec 2009
Lesson 1: Buttons and Events – 12/18
Using Visual Studio with C#
Important terms Black-box testing White-box testing Regression testing
Important terms Black-box testing White-box testing Regression testing
Introducing the… Distributive Property
TRANSLATORS AND IDEs Key Revision Points.
While loops The while loop executes the statement over and over as long as the boolean expression is true. The expression is evaluated first, so the statement.
Debugging with Eclipse
Number and String Operations
DEBUGGING JAVA PROGRAMS USING ECLIPSE DEBUGGER
Tonga Institute of Higher Education
Topic 1: Problem Solving
Coding Concepts (Standards and Testing)
Using a Debugger 1-Jan-19.
Debugging Taken from notes by Dr. Neil Moore
Testing, debugging, and using support libraries
Error Analysis Runtime Errors.
Due Next Monday Assignment 1 Start early
Debugging Taken from notes by Dr. Neil Moore
IDE’s and Debugging.
Access: Reports Participation Project
Tonga Institute of Higher Education IT 141: Information Systems
Tonga Institute of Higher Education IT 141: Information Systems
Review of Previous Lesson
Software Development Techniques
Debugging with Eclipse
Presentation transcript:

Error Analysis Logic Errors

Review So far we have discussed two categories of errors: Syntax Errors: We see these at Design Time, before the program runs Runtime Errors: We see these at Runtime, as the program runs Today’s topic is the scariest category of error for the programmer because it may go unseen potentially forever.

Logic Errors A logic error is an error that prevents the program from doing what it is intended to do, producing unexpected results: This could be something nice and simple like adding when you meant to multiply while calculating the area of a rectangle Or something much more complicated like two objects passing through one another in a game that should have collided. The program still runs and finishes fine, but not with the results you were expecting.

Logic Errors These are the hardest errors to find and fix because the program does not actually break We do not necessarily know what the cause of the error is, and in some cases the error may not be even seen for the first time until years after the product has been in the consumer’s hands. These are the errors that will cause a programmer the most stress, yet are the ones every programmer feels most proud of when they solve.

Let’s Try an Easy One… double radius = 0; double area; area = 2 * Math.PI * radius; System.out.println(“The area is: “ + area); Wrong equation, PI * radius2

Remedy Similar to runtime errors, the only way to prevent logic errors is testing. However, when a logic error is found there unfortunately is no sure fire way to solve the problem. As said before, you may not even know where in your program the exists. Let’s take the two examples given in the beginning: In the first example, the logic error was adding when we should have multiplied the length and width to get the area. This is simple to solve because during the process of using the software people would quickly see that their area was always smaller than it should be. So the natural place to look would be the area calculation code

Remedy In the second example we stated that two objects moved through one another in a video game that should have collided. This is an extremely complicated issue and can be the result of any number of problems leading up to the test looking for a collision. In this case, as in most logic errors, it is best to start at the end and work backwards. Meaning, find the code that does the collision test and examine the values of variables and determine which, if any, are out of sorts. When this is done, find out why the data is bad working your way backwards to where that data was set, and so on.

The Debugger To help us in the process of debugging our programs we can force the Debug Perspective and use its many helpful tools. In the screen shot you can see the program in the Java Perspective. Beside one of the lines on the left you see a blue dot. This is called a break-point and it was manually placed by double-clicking in that blue bar.

The Break-Point A break-point is like a pause point for our program, when we run our program using F11 (or Bug button) it will execute as normal until the code gets to the break-point line and will pause execution AND change to the Debug Perspective. It is sitting on that line, but not executing it until we tell it to. This is the most valuable tool in debugging code. When the program is paused we can mouse-over any variable and see its current value. We can also start stepping through the code executing one line at a time.

Stepping Through the Code We have the following controls while the program is paused to help us “step- through” our code one line at a time: Mouse over a variable to see its current value Select a variable OR expressionright-click itWatch: This will add it to the Expressions tab in the top right of the Debug perspective and will give you a constant watch of its value so you do not have mouse-over anymore. F6: Execute the current line of code fully F5: Go-into the next subprogram on the current line of code (only useful if it is your subprogram and not a prebuilt Java one) F8: Resume program as normal (this will pause again if it gets to another break-point)