BIM313 – Advanced Programming Techniques Debugging 1.

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

Topics Introduction Types of Errors Exceptions Exception Handling
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
Why care about debugging? How many of you have written a program that worked perfectly the first time? No one (including me!) writes a program that works.
Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
C# Programming: From Problem Analysis to Program Design1 Debugging and Handling Exceptions C# Programming: From Problem Analysis to Program Design 3 rd.
Chapter 11 Debugging and Handling Exceptions
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.
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
Finding and Debugging Errors
How to Debug VB .NET Code.
Guidelines for working with Microsoft Visual Studio.Net.
Visual Basic Debugging Tools Appendix D 6/27/20151Dr. Monther Aldwairi.
Guidelines for working with Microsoft Visual Studio 6.
Chapter 12: Advanced Topics: Exception Handling Visual Basic.NET Programming: From Problem Analysis to Program Design.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
JavaScript, Fourth Edition
DEBUGGERS For CS302 Data Structures Course Slides prepared by TALHA OZ (most of the text is from
Debugging Logic Errors CPS120 Introduction to Computer Science Lecture 6.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering.
ASP.NET Programming with C# and SQL Server First Edition Chapter 6 Debugging and Error Handling.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - HelloWorld Application: Introduction to.
Debugging applications, using properties Jim Warren – COMPSCI 280 S Enterprise Software Development.
DEBUGGING CHAPTER Topics  Getting Started with Debugging  Types of Bugs –Compile-Time Bugs –Bugs Attaching Scripts –Runtime Errors  Stepping.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC BUILDING BLOCKS Bilal Munir Mughal 1 Chapter-5.
Debugging Projects Using C++.NET Click with the mouse button to control the flow of the presentation.
BİL528 – Bilgisayar Programlama II Making Decisions, Loops, Debugging, Designing Objects Using Classes 1.
Dealing with Errors. Error Types Syntax Errors Runtime Errors Logical Errors.
Our Environment We will exercise on Microsoft Visual C++ v.6 We will exercise on Microsoft Visual C++ v.6 because that is what we have in the univ. because.
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
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.
Introduction to Exception Handling and Defensive Programming.
Program Errors and Debugging Week 10, Thursday Lab.
VB – Debugging Tools Appendix D. Why do we need debugging? Every program has errors, and the process of finding these errors is debugging Types of errors.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Module 6: Debugging a Windows CE Image.  Overview Debug Zones IDE Debug Setup IDE Debug Commands Platform Builder Integrated Kernel Debugger Other Debugging.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.
CS Class 05 Topics  Selection: switch statement Announcements  Read pages 74-83, ,
Debugging Visual Basic.NET Programs ► ► Use debugging tools ► ► Set breakpoints and correct mistakes. ► ► Use a Watch and Local window to examine variables.
Debugging Xin Tong. GDB GNU Project debugger Allows you to see what is going on `inside' another program while it executes or crashed. (Faster than printing.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
1 Debugging and Syntax Errors in C++. 2 Debugging – a process of finding and fixing bugs (errors or mistakes) in a computer program.
School of Computer Science & Information Technology G6DICP - Lecture 6 Errors, bugs and debugging.
Lab00-Getting Started with VC Launch VS 2005 Launch Visual Studio 2005 – Start > All Programs > Microsoft Visual Studio 2005 > Microsoft Visual.
Debug in Visual Studio Windows Development Fundamentals LESSON 2.5A.
Debugging tools in Flash CIS 126. Debugging Flash provides several tools for testing ActionScript in your SWF files. –The Debugger, lets you find errors.
Visual Basic Integrated Development Environment (IDE) 56:150 Information System Design.
CSC 1201 LAB RULES Nouf Aljaffan (C) CSC 1201 Course at KSU.
JavaScript, Sixth Edition
An introduction to the debugger And jGrasp editor-syncrasies (ideosyncrasies)
COMPUTER PROGRAMMING I SUMMER Understand Different Types of Programming Errors.
Exception Handling. VB.NET has an inbuilt class that deals with errors. The Class is called Exception. When an exception error is found, an Exception.
1 Handling Errors and Exceptions Chapter 6. 2 Objectives You will be able to: 1. Use the try, catch, and finally statements to handle exceptions. 2. Raise.
Introduction to ASP.NET, Second Edition2 Chapter Objectives.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
Debuggers. Errors in Computer Code Errors in computer programs are commonly known as bugs. Three types of errors in computer programs –Syntax errors –Runtime.
Chapter 2: The Visual Studio .NET Development Environment
Debugging and Handling Exceptions
ME 142 Engineering Computation I
How to debug an application
Testing and Debugging.
Computer Programming I
5.01 Understand Different Types of Programming Errors
Debugging 9/22/15 & 9/23/15 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Testing, debugging, and using support libraries
Our Environment We will exercise on Microsoft Visual C++ v.6
Debugging Visual Basic Programs
Presentation transcript:

BIM313 – Advanced Programming Techniques Debugging 1

Contents Debugging and Error Handling – Debugging feature in Visual Studio – try … catch … finally 2

Debugging and Error Handling 3

Error Types Syntax Errors – Forgetting semicolon, not closing parentheses or curly braces, writing variable name incorrectly, etc. – Program is not compiled – Examine the compiler errors and correct the codes Logical Errors – Program is compiled – Program does not give the desired output – Debug your program! 4

Debugging in Visual Studio Put breakpoints in your code – F9, click at the beginning of a line, Debug menu Start your program in Debug mode – F5 (not Ctrl-F5), Play arrow in toolbar, Debug menu Press F10 for single step Press F11 to enter a function End debugging with Shift-F5 or Stop in toolbar 5

Monitoring Variable Content Move cursor an a variable while program is being debugged Follow the variables in the Locals and Autos windows Add variables into the Watch windows Use the Immediate Window – Write the name of the variable and press Enter – You can call functions and expressions too 6

Configurations Debug – Extra symbols are included in the executable file so that it can be debugged – Runs slowly – Executable file size larger Release – Runs faster – Executable file size smaller – Use this configuration on the last build (before distributing your program) 7

Debugging Without a Debugger A debugger (e.g. Visual Studio) makes debugging easier If you don’t have an IDE, you can use Console.WriteLine() to debug your programs Just call Console.WriteLine() to print variables or some useful messages Don’t forget to remove those lines in the last build 8

Debugging in Nonbreaking (Normal) Mode Console.WriteLine("MyFunc() Function about to be called."); MyFunc("Do something."); Console.WriteLine("MyFunc() Function execution completed."); 9

Some Advanced Topics Debug.WriteLine() / Trace.WriteLine() Debug.WriteLineIf() / Trace.WriteLineIf() Debug.Assert() / Trace.Assert() using System.Diagnostics; You can set number of hits and hit condition for breakpoints – Just right-click on the red dot of the breakpoint 10

Error Handling (try..catch..finally) While running a program through the IDE (i.e. during the development step, or Debug mode), you receive an error message if an error occurs. However, if your program runs in the final version (or Release mode), an error causes your program to terminate. For these cases, you may prefer using structured exception handling (or try..catch..finally) 11

Sections of the try Structure try: The try section is where you place code that might cause an exception. catch: Code within the catch section executes only when an exception occurs. finally: Code within the finally section occurs when the code within the try and/or catch sections completes. This section is where you place your cleanup code—code that you always want executed, regardless of whether an exception occurs. 12

try Example int number = int.Parse(Console.ReadLine()); int result = 100 / number; string str = result.ToString(); 13 An error may occur while converting a text into an integer! An error may occur if the number is zero!

try Example – Solution 1 try { int number = int.Parse(Console.ReadLine()); int result = 100 / number; string str = result.ToString(); } catch { Console.WriteLine(“An error has occurred!”); } 14

try Example – Solution 2 try { int number = int.Parse(Console.ReadLine()); int result = 100 / number; string str = result.ToString(); } catch (ArgumentException ex1){ Console.WriteLine(“An ArgumentException error occurred!”); } catch (DivideByZeroException ex2) { Console.WriteLine(“The divisor can’t be zero”); } catch (Exception ex) { Console.WriteLine(“An unspecified error occurred. The details is: ” + ex.Message); } 15

try Example – Solution 3 int result = 0; string strResult; try { int number = int.Parse(Console.ReadLine()); result = 100 / number; } catch (Exception ex) { Console.WriteLine(“An unspecified error occurred. The details is: ” + ex.Message); } finally { strResult = result.ToString(); } 16

try Example on Database Operations try { … // Open database … // Make some operations on the database } catch { … // Error handling statements } finally { … // Close the database } 17