Debugging Techniques1. 2 Introduction Bugs How to debug Using of debugger provided by the IDE Exception Handling Techniques.

Slides:



Advertisements
Similar presentations
Topics Introduction Types of Errors Exceptions Exception Handling
Advertisements

COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
An Introduction to Java Programming and Object- Oriented Application Development Chapter 8 Exceptions and Assertions.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 15: Exception Handling.
C# Programming: From Problem Analysis to Program Design1 Debugging and Handling Exceptions C# Programming: From Problem Analysis to Program Design 3 rd.
Chapter 16: Exception Handling C++ Programming: From Problem Analysis to Program Design, Fifth Edition.
Objectives In this chapter you will: Learn what an exception is Learn how to handle exceptions within a program See how a try / catch block is used to.
Chapter 11 Debugging and Handling Exceptions
© The McGraw-Hill Companies, 2006 Chapter 15. © The McGraw-Hill Companies, 2006 Exceptions an exception is an event that occurs during the life of a program.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 16: Exception Handling.
Slides prepared by Rose Williams, Binghamton University ICS201 Exception Handling University of Hail College of Computer Science and Engineering Department.
Microsoft VB 2005: Reloaded, Advanced Chapter 5 Input Validation, Error Handling, and Exception Handling.
Program Correctness and Efficiency Chapter 2. Chapter 2: Program Correctness and Efficiency2 Chapter Objectives To understand the differences between.
Exceptions in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
1 Chapter 4 The Fundamentals of VBA, Macros, and Command Bars.
Finding and Debugging Errors
Java Review 2 – Errors, Exceptions, Debugging Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Chapter 12: Advanced Topics: Exception Handling Visual Basic.NET Programming: From Problem Analysis to Program Design.
Chapter 11: Handling Exceptions and Events J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Fourth.
12.1 Exceptions The limitations of traditional methods of exception handling Error conditions are a certainty in programming Programmers make.
Exceptions COMPSCI 105 S Principles of Computer Science.
1 Chapter Eight Exception Handling. 2 Objectives Learn about exceptions and the Exception class How to purposely generate a SystemException Learn about.
ASP.NET Programming with C# and SQL Server First Edition Chapter 6 Debugging and Error Handling.
Object Oriented Programming
CIS 270—Application Development II Chapter 13—Exception Handling.
Chapter 12: Exception Handling
UNIT 3 TEMPLATE AND EXCEPTION HANDLING. Introduction  Program errors are also referred to as program bugs.  A C program may have one or more of four.
COMPUTER PROGRAMMING 2 Exceptions. What are Exceptions? Unexpected events that happen when the code is executing (during runtime). Exceptions are types.
Exception Handling. 2 Two types of bugs (errors) Logical error Syntactic error Logical error occur  Due to poor understanding of the problem and solution.
Programming Translators.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC BUILDING BLOCKS Bilal Munir Mughal 1 Chapter-5.
VB Core II Conditional statements Exception handling Loops Arrays Debugging.
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.
VB.Net - Exceptions Copyright © Martin Schray
Object Oriented Software Development 8. Exceptions, testing and debugging.
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.
Introduction to Exception Handling and Defensive Programming.
Chapter 14: Exception Handling. Objectives In this chapter, you will: – Learn what an exception is – Learn how to handle exceptions within a program –
Exception Handling Unit-6. Introduction An exception is a problem that arises during the execution of a program. An exception can occur for many different.
MS Visual Basic Applications Walter Milner. Event-driven programming Standard approach for GUIs Contrast with old character interfaces – program determines.
Controlling Execution Programming Right from the Start with Visual Basic.NET 1/e 8.
Exceptions in Java. Exceptions An exception is an object describing an unusual or erroneous situation Exceptions are thrown by a program, and may be caught.
Chapter 12 Handling Exceptions and Events. Chapter Objectives Learn what an exception is Become aware of the hierarchy of exception classes Learn about.
CSE 332: C++ debugging Why Debug a Program? When your program crashes –Finding out where it crashed –Examining program memory at that point When a bug.
Sheet 3 HANDLING EXCEPTIONS Advanced Programming using Java By Nora Alaqeel.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 11 Handling Exceptions and Events.
Exceptions and Assertions Chapter 15 – CSCI 1302.
CSE 332: C++ Statements C++ Statements In C++ statements are basic units of execution –Each ends with ; (can use expressions to compute values) –Statements.
Exception Handling in Java Topics: Introduction Errors and Error handling Exceptions Types of Exceptions Coding Exceptions Summary.
11. EXCEPTION HANDLING Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
Chapter 15: Exception Handling C++ Programming: Program Design Including Data Structures, Fifth Edition.
CS212: Object Oriented Analysis and Design Lecture 19: Exception Handling.
Programming & Debugging. Key Programming Issues Modularity Modifiability Ease of Use Fail-safe programming Style Debugging.
1 Exceptions. 2 Syntax Errors, Runtime Errors, and Logic Errors syntax errors, runtime errors, and logic errors You learned that there are three categories.
CMSC 202 Computer Science II for Majors. CMSC 202UMBC Topics Exceptions Exception handling.
Lecture10 Exception Handling Jaeki Song. Introduction Categories of errors –Compilation error The rules of language have not been followed –Runtime error.
Exception Handling How to handle the runtime errors.
COMPUTER PROGRAMMING I SUMMER Understand Different Types of Programming Errors.
Exception and Exception Handling. Exception An abnormal event that is likely to happen during program is execution Computer could run out of memory Calling.
ECE122 L23: Exceptions December 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 24 Exceptions.
Debuggers. Errors in Computer Code Errors in computer programs are commonly known as bugs. Three types of errors in computer programs –Syntax errors –Runtime.
Exceptions Exceptions are used to signal that an unexpected event has happened in a program C++ will generate exceptions for some errors in the program.
Debugging and Handling Exceptions
Programming in visual basic .net Visual Basic Building Blocks
CS1101X Programming Methodology
Testing and Debugging.
Chapter 14: Exception Handling
Exception Handling.
Presentation transcript:

Debugging Techniques1

2 Introduction Bugs How to debug Using of debugger provided by the IDE Exception Handling Techniques

Debugging Techniques3 Bugs/Errors Main types –Syntax error –Logic error –Runtime error

Debugging Techniques4 Syntax Error A syntax error refers to a mistake in a statement's syntax.syntax A fatal error that the programmer must correct before being able to fully compile the program.fatal errorprogrammerprogram Can be indicated by the compilers Some IDEs are able to display syntax errors in real-time.IDEs

Debugging Techniques5 Logic Error A Logic Error is a bug in a program that causes unexpected results or operation but not failure. Cannot be checked by the compilers, as the program is syntactically valid. Logic errors are usually the hardest to debug because they do not cause the program to fail completely. A common technique in solving logic errors is to print the program's variables to a file or the console in order to isolate where the problem is.

Debugging Techniques6 Runtime Error / Exception A Runtime Error (Exception) is a problem that arise when the program is executed. E.g. divide by zero, array out of bounds

Debugging Techniques7 How to Debug? Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a computer program.bugscomputer program The basic steps in debugging are: –Recognize that a bug exists –Isolate the source of the bug –Identify the cause of the bug –Determine a fix for the bug –Apply the fix and test it Tools –Walk through your program –Display the variables at certain points, trace the program –Use of professional debugger

Debugging Techniques8 Testing Methods (1) Exhaustive testing –Test a program with all possible data values –Not feasible Black box (functional) testing –Treat the unit of testing as a Black Box (with inputs and outputs) only, and test its function –Black box testing takes an external perspective of the test object to derive test cases. The test designer selects valid and invalid input and determines the correct output. There is no knowledge of the test object's internal structure. –The key is to devise sample data that is representative of all possible data

Debugging Techniques9 Testing Methods (2) White box (structural) testing –Make use of knowledge of how the program works, its structure –White box testing uses an internal perspective of the system to design test cases based on internal structure. It requires programming skills to identify all paths through the software. The tester chooses test case inputs to exercise all paths and determines the appropriate outputs. –Test all execution paths Inspections and Walkthroughs

Debugging Techniques10 Visual Studio.NET Debugger

Debugging Techniques11 Stepping through Code Modern debuggers usually allow you to step through your program and look at the values of variables Also the debugger will allow you to set breakpoints, which are statements in your programs that you mark and tell the debugger to suspend program execution when it gets there Tools –Start, Stop, Break, Restart –Step Into Executes the next statement even if it’s inside a new procedure –Step Out Finishes executing the current procedure and stops when control returns to the calling procedure –Step Over Executes the next statement. If that statement is a procedure, the procedure is executed without stopping Autos, Locals, Watch windows Call Stack window

Debugging Techniques12 Exception Handling Syntax errors can be caught by the compiler and signaled by the IDE Runtime errors (exceptions) are problems that arise when the program is executed –E.g. result = x / y –This is a valid statement but what if y = 0? –The program will be interrupted, and an exception will be thrown –An Exception is an object of a special data type (Exception) that is generated as a result of the error and it contains information about the runtime error Your program should handle the exceptions, instead of letting it dump Two exception handling approaches –Unstructured Exception Handling –Structured Exception Handling

Debugging Techniques13 Unstructured Exception Handling An older technique of dealing with exceptions In previous versions of VB, an global object named Err is used to indicate the error An error handler is a statement that tells the runtime what to do if an error occurs Or using If statements to check for errors

Debugging Techniques14 Unstructured Exception Handling Module Module1 Sub Main() Dim i, j As Integer On Error Goto Main_Failed i = i \ j Exit Sub Main_Failed: If err.Number = 11 Then‘ DivideByZeroException j = 1 Resume‘ re-execute the same statement ElseIf err.Number = 10 Then Resume Next‘ ignore the offending statement and continue Else MsgBox(Err.Description) End If End Sub End Module

Debugging Techniques15 Structured Exception Handling (1) A modern approach to Exception Handling Try-Catch statement Try block consists of the statement(s) that you believe may cause exceptions to be thrown Catch block is the exception handler which specifies what to do in case of error If an exception occurs while executing the code in the Try block, the program execution is interrupted, and the control is passed to the appropriate Catch handler There may be more than one catch block, each for a specific type of exception

Debugging Techniques16 Structured Exception Handling (2) Dim i As Integer = 5 Dim j As Integer = 0 Dim result As Integer Try result = i \ j Catch e As DivideByZeroException MsgBox("We caught a divide by 0 exception") End Try

Debugging Techniques17 Structured Exception Handling (3) Can have multiple Catch blocks (Example ExceptionExample) Dim i As Integer = 5 Dim result As Integer Try result = Integer.MaxValue * i Catch e As DivideByZeroException MsgBox("We caught a divide by 0 exception") Catch e As Exception MsgBox("We caught generic exception") System.Console.Out.WriteLine(e.StackTrace) Throw‘ re-throw for some other handler to deal with it End Try

Debugging Techniques18 Structured Exception Handling (4) Exceptions are propagated on the call stack (Example ExceptionExample2) Module Module1 Sub Main() Dim result As Integer Try result = MultiplyInts(Integer.MaxValue, 5) Catch e As DivideByZeroException MsgBox("We caught a divide by 0 exception") Catch e As Exception MsgBox("We caught generic exception") System.Console.Out.WriteLine(e.StackTrace) End Try End Sub Function MultiplyInts(ByVal i As Integer, ByVal j As Integer) As Integer Dim result As Integer result = i * j Return result End Function End Module

Debugging Techniques19 Structured Exception Handling (5) Try … Catch … Finally ‘ Code that will always be executed End Try