MOOR ERROR HANDLING Types of error How to test your code for errors How to detect errors How to recover from errors.

Slides:



Advertisements
Similar presentations
Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
Advertisements

SOFTWARE TESTING. INTRODUCTION  Software Testing is the process of executing a program or system with the intent of finding errors.  It involves any.
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
PHYS 2020 Pseudocode. Real Programmers Program in Pencil!  You can save a lot of time if you approach programming in a methodical way.  1) Write a clear.
Programming Types of Testing.
PSEUDOCODE & FLOW CHART
Debugging Techniques1. 2 Introduction Bugs How to debug Using of debugger provided by the IDE Exception Handling Techniques.
Lecture Roger Sutton CO331 Visual programming 15: Debugging 1.
16/27/2015 3:38 AM6/27/2015 3:38 AM6/27/2015 3:38 AMTesting and Debugging Testing The process of verifying the software performs to the specifications.
An Object-Oriented Approach to Programming Logic and Design Chapter 6 Looping.
Main task -write me a program
Chapter 1 Program Design
Week 7 - Programming II Today – more features: – Loop control – Extending if/else – Nesting of loops Debugging tools Textbook chapter 7, pages
PRE-PROGRAMMING PHASE
Debugging Logic Errors CPS120 Introduction to Computer Science Lecture 6.
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
Introduction to High-Level Language Programming
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering.
CC0002NI – Computer Programming Computer Programming Er. Saroj Sharan Regmi Week 7.
REPETITION STRUCTURES. Topics Introduction to Repetition Structures The while Loop: a Condition- Controlled Loop The for Loop: a Count-Controlled Loop.
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.
TESTING.
สาขาวิชาเทคโนโลยี สารสนเทศ คณะเทคโนโลยีสารสนเทศ และการสื่อสาร.
Programming Translators.
Chapter 5: Control Structures II (Repetition)
ICAPRG301A Week 4Buggy Programming ICAPRG301A Apply introductory programming techniques Program Bugs US Navy Admiral Grace Hopper is often credited with.
Chapter 3 Developing an algorithm. Objectives To introduce methods of analysing a problem and developing a solution To develop simple algorithms using.
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.
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
Conditions. Objectives  Understanding what altering the flow of control does on programs and being able to apply thee to design code  Look at why indentation.
DEBUGGING. BUG A software bug is an error, flaw, failure, or fault in a computer program or system that causes it to produce an incorrect or unexpected.
COMP 121 Week 1: Testing and Debugging. Testing Program testing can be used to show the presence of bugs, but never to show their absence! ~ Edsger Dijkstra.
Software Engineering Chapter 3 CPSC Pascal Brent M. Dingle Texas A&M University.
Chapter 5: Control Structures II (Repetition). Objectives In this chapter, you will: – Learn about repetition (looping) control structures – Learn how.
Review, Pseudocode, Flow Charting, and Storyboarding.
The Software Development Process
1 Program Planning and Design Important stages before actual program is written.
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.
1 Debugging and Syntax Errors in C++. 2 Debugging – a process of finding and fixing bugs (errors or mistakes) in a computer program.
CS 100 Introduction to Computing Seminar October 7, 2015.
Software Engineering 2004 Jyrki Nummenmaa 1 BACKGROUND There is no way to generally test programs exhaustively (that is, going through all execution.
Intermediate 2 Computing Unit 2 - Software Development.
More Python!. Lists, Variables with more than one value Variables can point to more than one value at a time. The simplest way to do this is with a List.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Repetition Structures.
CSC 1010 Programming for All Lecture 4 Loops Some material based on material from Marty Stepp, Instructor, University of Washington.
Error Handling Tonga Institute of Higher Education.
1 The Software Development Process ► Systems analysis ► Systems design ► Implementation ► Testing ► Documentation ► Evaluation ► Maintenance.
AVCE ICT – Unit 7 - Programming Session 12 - Debugging.
COMPUTER PROGRAMMING I SUMMER Understand Different Types of Programming Errors.
Progression in KS3/4 Algorithms MONDAY 30 TH NOVEMBER SUE SENTANCE.
Today… Python Keywords. Iteration (or “Loops”!) Winter 2016CISC101 - Prof. McLeod1.
Debugging and Testing Hussein Suleman March 2007 UCT Department of Computer Science Computer Science 1015F.
Debuggers. Errors in Computer Code Errors in computer programs are commonly known as bugs. Three types of errors in computer programs –Syntax errors –Runtime.
Topics Introduction to Repetition Structures
Testing and Debugging.
Software Design and Development
Lesson Outcomes Be able to identify differentiate between types of error in programs Be able to interpret error messages and identify, locate.
Computer Programming.
Week 8 - Programming II Today – more features: Loop control
Design and Programming
Tonga Institute of Higher Education
Debugging Taken from notes by Dr. Neil Moore
Test Case Test case Describes an input Description and an expected output Description. Test case ID Section 1: Before execution Section 2: After execution.
Debugging Taken from notes by Dr. Neil Moore
Data and Flowcharts Session
Data and Flowcharts Session
Review of Previous Lesson
ICS103: Programming in C 5: Repetition and Loop Statements
Presentation transcript:

MOOR ERROR HANDLING Types of error How to test your code for errors How to detect errors How to recover from errors

TYPES OF ERROR – THEORY   Recap: 3 main errors made by programmers (that is us!) 1. Syntax Errors – eg. silly typing errors 2. Run-time Errors – eg. it may run but crashes at some point 3. Logical Errors – eg. getting the code to run but it does something different  It is important to test a program to check if it is robust and not likely to break down.  A program is very unlikely to work perfectly the first time it is executed thus testing is carried out to try and make it fail or reveal the presence of errors.  Q. What are the consequences of software not being tested effectively? 1)The reputation of the company would be ruined 2)An accident could be caused if the code is used in a safety critical system eg. Aircraft/nuclear power station Debugging: the process of detecting and correcting errors during execution of a program.

DRY-RUN TESTING  Once you have an algorithm, pseudo-code or flow chart then a dry-run testing can be carried out.  This involves stepping through the algorithm one instruction at a time with purposely chosen data. A trace table is used by the programmer to track the test data.  Hopefully the table will help pinpoint where the problem is. Note, this form of testing is done on a small scale as it is hard going and very repetitive.  The main advantage of dry-run testing is that is enables programmers to spot errors even before they start writing code.

DRY-RUN TESTING Somebody on StackOverflow wrote: I am wondering? Why would the output not be: i1 j1 j2 i2 i3 and instead it is: i1 j1 j2 i2 j1 j2 i3 j1 j2 Why does the rightmost while loop keep repeating even though the value of j is already satisfied eventually by it. Answer: i= 1 while (i<=3): print("i",i) j=1 while (j<3): print("j",j) j=j+1 i=i+1 print("Done!") You are re-initializing your j to 1 in the outer while loop. So, every time your outer loop, starts, your inner loop will run two times. A trace table would be able to help find the source of the problem with all the variables and conditions along the top. Each time a variable/condition changes you go one row down and enter into the table. j

UNIT TESTING  This is a popular means of testing a program by writing additional programs that test a specific function of a main program.  This is useful for massive programs so you focus on a small piece of the code or a specific module.  Unit testing is an automatic tool that can uncover regressions. These are unwanted changes in previously working code which may have been introduced during the development.  Code coverage is a term that is used to describe the percentage of lines of code that are covered by unit tests. Eg. A def function or a specific looping structure.  Remember: we are looking for bugs which are the key annoyance to any programmer!

DEBUGGING  To debug code effectively 2 things are needed:  The ability to test each of the instructions provided by the program  The ability to retrieve the information about:  The results of the instructions  Any changes in the program when the tests were carried out  The error conditions  What the program was doing when the error occurred.  Thank goodness for our software tools in Eclipse to help in the debugging process.  The interpreter will detect syntax errors prior to running the program.  Problems will be flagged up:  Then the interpreter will detect run-time errors when you run the program.  You have to find logical errors yourself!  There are 3 specific feature to look at in our debugging work:  Breakpoints …. Steps … Watches …lets get debugging…

Copy the following code into Idle, save as “RPS”: import random,time def WhoWins(you,computer): if you == ("rock"): if computer == ("scissors"): return 1 # You win elif computer == ("rock"): return 2 # draw elif computer == ("paper"): return 3 # Computer wins elif you == ("paper"): if computer == ("rock"): return 1 # You win elif computer == ("paper"): return 2 # draw elif computer == ("scissors"): return 3 # Computer wins elif you == ("scissors"): if computer == ("paper"): return 1 # You win elif computer == ("scissors"): return 2 # draw elif computer == ("rock"): return 3 # Computer wins else: return 0 # invalid input option = ["rock", "paper","scissors"] wins = 0 loses = 0 draws = 0 while True: print("wins =", wins) print("loses =", loses) print("draws =", draws) you = input("rock,paper or scissors: ") computer = random.choice(option) time.sleep(1) print("you picked", you) time.sleep(1) print("computer picked", computer) time.sleep(1) winner=WhoWins(you,computer) if winner == 1: # you won print("you win") wins += 1 elif winner == 2: print("draw") draws += 1 elif winner == 3: print("you lose") loses += 1 else: print("invalid input")

Instructions: Put a breakpoint in “RPS”. Once the program is paused the debugger allows the tester to continue the execution of the program one line at a time; effectively stepping through the program. This allows a programmer to see exactly how many variables and objects are affected when a particular line is executed. Work through the step over, step into and step return. Note the variables being assigned in the debugger. Find the watch table (top right corner). Look at how the debugger sorts the variables. Consider the scope when inside a function. Make any other observations to see how the sub-routine (function) operates. Use the debugger next time you write a program to help detect errors