Jun 16, 2014IAT 2651 Debugging. Dialectical Materialism  Dialectical materialism is a strand of Marxism, synthesizing Hegel's dialectics, which proposes.

Slides:



Advertisements
Similar presentations
11-Jun-14 The assert statement. 2 About the assert statement The purpose of the assert statement is to give you a way to catch program errors early The.
Advertisements

Exceptions: when things go wrong. Various sources of error public static doSomething() { int i = 3.0; while(!done); { int i = false } ) Syntactic errors.
Yoshi
Introduction to Exceptions in Java. 2 Runtime Errors What are syntax errors? What are runtime errors? Java differentiates between runtime errors and exceptions.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 13 Exception Handling.
EXCEPTIONS. What’s an exception?? Change the flow of control when something important happens ideally - we catch errors at compile time doesn’t happen.
Exception Handling Chapter 12.  Errors- the various bugs, blunders, typos and other problems that stop a program from running successfully  Natural.
Slides prepared by Rose Williams, Binghamton University ICS201 Exception Handling University of Hail College of Computer Science and Engineering Department.
Testing and Error Handling Intro to Java. Testing We test to try and make sure our programs work correctly and have no bugs If we have access to the code,
Lecture 27 Exceptions COMP1681 / SE15 Introduction to Programming.
Debugging Introduction to Computing Science and Programming I.
Nov 10, Fall 2006IAT 8001 Debugging. Nov 10, Fall 2006IAT 8002 How do I know my program is broken?  Compiler Errors –easy to fix!  Runtime Exceptions.
11-Jun-15 Exceptions. 2 Errors and Exceptions An error is a bug in your program dividing by zero going outside the bounds of an array trying to use a.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 17 Exceptions and.
16-Jun-15 Exceptions. Errors and Exceptions An error is a bug in your program dividing by zero going outside the bounds of an array trying to use a null.
Exceptions in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
18-Jun-15 Arrays. 2 A problem with simple variables One variable holds one value The value may change over time, but at any given time, a variable holds.
Exceptions. Errors and Exceptions An error is a bug in your program –dividing by zero –going outside the bounds of an array –trying to use a null reference.
Java Review 2 – Errors, Exceptions, Debugging Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Debugging CMSC 201. Announcements Hw2, Hw3 grades returned if something doesn’t seem right, ask Midterm next Thurs (Oct 23) we’ll review on Tues no hw.
Hello AP Computer Science!. What are some of the things that you have used computers for?
June 14, 2001Exception Handling in Java1 Richard S. Huntrods June 14, 2001 University of Calgary.
Chapter 12: Exception Handling
Java Programming Exception Handling. The exception handling is one of the powerful mechanism provided in java. It provides the mechanism to handle the.
Coding Methodology How to Design Code. © 2005 MIT-Africa Internet Technology Initiative Pay Attention to Detail When implementing or using APIs details.
Exceptions 1. Your computer takes exception Exceptions are errors in the logic of a program (run-time errors). Examples: Exception in thread “main” java.io.FileNotFoundException:
Debugging !!!  ► Believe it or not, errors happen ► The most frustrating part of programming ► Hunting down an error can be harder and more time consuming.
C Programming Tutorial – Part I CS Introduction to Operating Systems.
07 Coding Conventions. 2 Demonstrate Developing Local Variables Describe Separating Public and Private Members during Declaration Explore Using System.exit.
The Java Programming Language
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
1 Debugging. 2 A Lot of Time is Spent Debugging Programs Debugging. Cyclic process of editing, compiling, and fixing errors. n Always a logical explanation.
JSP Exception Handling 20-Oct-15. JSP - E XCEPTION H ANDLING When you are writing JSP code, a programmer may leave a coding errors which can occur at.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
Security - Why Bother? Your projects in this class are not likely to be used for some critical infrastructure or real-world sensitive data. Why should.
1 C++ Classes and Data Structures Jeffrey S. Childs Chapter 4 Pointers and Dynamic Arrays Jeffrey S. Childs Clarion University of PA © 2008, Prentice Hall.
Practice Session 9 Exchanger CyclicBarrier Exceptions.
Documentation Dr. Andrew Wallace PhD BEng(hons) EurIng
FT228/3 Web Development Error processing. Introduction READ Chapter 9 of Java Server Pages from O’reilly 2 nd Edition Need to be able to 1) Diagnose and.
AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors
Hello Computer Science!. Below is an example of a Hello World program in JAVA. While it is only three lines of code, there are many things that are happening.
School of Computer Science & Information Technology G6DICP - Lecture 6 Errors, bugs and debugging.
Exception Handling in Java Topics: Introduction Errors and Error handling Exceptions Types of Exceptions Coding Exceptions Summary.
ICS3U_FileIO.ppt File Input/Output (I/O)‏ ICS3U_FileIO.ppt File I/O Declare a file object File myFile = new File("billy.txt"); a file object whose name.
CIT 590 Intro to Programming Lecture 13. Some Eclipse shortcuts CTRL + SHIFT + F – format file (proper indentation etc). Please do this before you submit.
Error Handling Tonga Institute of Higher Education.
CS116 COMPILER ERRORS George Koutsogiannakis 1. How to work with compiler Errors The Compiler provide error messages to help you debug your code. The.
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.
Exceptions Lecture 11 COMP 401, Fall /25/2014.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
And other languages…. must remember to check return value OR, must pass label/exception handler to every function Caller Function return status Caller.
Exception. Agenda Exception. Handling Exceptions. The finally Clause.
Throw, Throws & Try-Catch Statements Explanations and Pictures from: Reference:
Exceptions and Error Handling. Exceptions Errors that occur during program execution We should try to ‘gracefully’ deal with the error Not like this.
Introduction to Exceptions in Java CS201, SW Development Methods.
Winter 2006CISC121 - Prof. McLeod1 Last Time Reviewed class structure: –attributes –methods –(inner classes) Looked at the effects of the modifiers: –public.
Lecture 5: Exception Handling and Text File I/O Michael Hsu CSULA.
Garbage Collection It Is A Way To Destroy The Unused Objects. To do so, we were using free() function in C language and delete() in C++. But, in java it.
CSE 332: C++ Exceptions Motivation for C++ Exceptions Void Number:: operator/= (const double denom) { if (denom == 0.0) { // what to do here? } m_value.
Eighth Lecture Exception Handling in Java
Exceptions In this lecture:
Chapter 10 – Exception Handling
Tirgul 13 Exceptions 1.
Testing and Debugging.
Week 14 - Wednesday CS 121.
Creating and Modifying Text part 2
Homework Any Questions?.
Exceptions 10-May-19.
Presentation transcript:

Jun 16, 2014IAT 2651 Debugging

Dialectical Materialism  Dialectical materialism is a strand of Marxism, synthesizing Hegel's dialectics, which proposes that  Every economic order grows to a state of maximum efficiency, while simultaneously developing internal contradictions and weaknesses that contribute to its systemic decay Jun 16, 2014IAT 2652

Dialectics  Thus, programming is a dialectic process: –ENbugging –Debugging  Karl Marx said so! Jun 16, 2014IAT 2653

Jun 16, 2014IAT 2654 How do I know my program is broken?  Compiler Errors –easy to fix!  Runtime Exceptions –more difficult to fix, but at least you're using java and these get reported  Your program just doesn't do the right thing.

Jun 16, 2014IAT 2655 Compiler Errors  Errors dealing with language syntax  Simple logical errors –Whatever the compiler can possibly catch.  Generally, the line number stated has the error on it –Sometimes the fix is elsewhere

Jun 16, 2014IAT 2656 How to fix compiler errors?  Start at the top of the error list  Some errors cause others –Wrong variable declaration causes errors in usage of that variable  Use the line number!  If that line looks OK, check the line above –maybe missed a brace/semicolon or other necessary syntax element.

Count Brackets and Braces { qwdkj { dw wqdlk lqwd { n,mnwq } } } Jun 16, 2014IAT Braces match if the last == 0!

Jun 16, 2014IAT 2658 Compile Time Errors  Some errors aren't necessarily errors. –For example: String foo; //assume we initialize this somewhere else public void blah(){ Object bar; try{ bar = foo.toString(); } catch(Exception e){ println(“Oh no!!”); return; } println(bar.toString()); //lets call this line 101 } –Will give you something like: line 101: variable bar might not be initialized! (or something like that)

Jun 16, 2014IAT 2659 print your variables  println() –Use println often –Print everything: array values, pointer values, array index, objects etc –Each println should label itself with class name and line number –Java: Be sure to use System.out.flush(); to ensure you are getting all data

Jun 16, 2014IAT Learn to read your code  Keep a notepad around to keep track of variable values. –Use comments to document complex code –Keep one step to one line. –Format your code! Indentations help readability –Keep your code neat: save your mental effort for understanding, not reading

Always the Same Place  My keys are always the same place: –Right front pocket  My Java variables are always the same place –Top of method or top of class  Why? –I always know where to look for variables! Jun 16, 2014IAT 26511

Always the Same Place  For loops: always formatted the same  Switch: always formatted the same  Variables: I reuse the same names for( int i = 0 ; i < arr.size() ; i++ ) {... }  Doing it the same way every time Means: –You don’t have to read the whole for loop Jun 16, 2014IAT 26512

Always the Same Place  Here’s what you see: for( int i = 0 ; i < arr.size() ; i++ ) { }  Here’s what I see: for( int i = 0 ; i < arr.size() ; i++ ) { }  Here’s what I see when something’s missing: for int i = 0 ; i < arr.size() ; i++ ) { } Jun 16, 2014IAT 26513

Always the Same Place  Doing something the same way allows me to notice when something is different Jun 16, 2014IAT 26514

Jun 16, 2014IAT Runtime Exceptions  There are two types of Runtime Exceptions –Checked and Unchecked  Checked exceptions: –Java makes you deal with these in your code –Things that you would expect to fail: I/O mainly  Unchecked exceptions –Java does not require you to catch these

Jun 16, 2014IAT Checked Exceptions  IOException (FileNotFoundException)  Input and output is typically hard to write because you have to deal with the real world’s complexities  Java requires that you put these in Try/Catch Blocks –Processing manages some of this

Jun 16, 2014IAT Unchecked Exceptions  Exceptions that only the programmer can anticipate –Extremely hard for a compiler to determine  NullPointerException (NPE) and ArrayIndexOutOfBoundsException (AIOBE)  Caused by semantic errors –uninitialized variable, bad loop logic…

Jun 16, 2014IAT Exceptions  On exception, you get a stack trace  Find the first line of the stack trace that occurs in your program.  That line is where the exception occurred, not necessarily where the fix is. –On that line, did you get an NPE? –Is there some object that you're calling a method on? Is that object Null? –For AIOBE, check index values

Jun 16, 2014IAT Things to remember  In java Objects are passed by reference and primitives are passed by value. public void doStuff(String a) { a = a + “bar”; } public void doMoreStuff(int a) { a = a+5; } public static void main(...){ String temp = “foo”; int temp2 = 5; doStuff(temp); doMoreStuff(temp2); System.out.println (temp); System.out.println (temp2); } prints out: foobar 5

Jun 16, 2014IAT The #1 debugging tip  TEST YOUR CODE OFTEN! –Catching your small errors early will help you avoid the big complicated errors later. –If you write a chunk of code that you can test, test it. –You'll regret not spending 5 minutes writing a simple test case when you spend hours trying to find out it has a bug later.

Wrong and Right  Build  Test  Build  Test  Build  Test  Build  Test  Build  Test Jun 16, 2014IAT 26521