School of Computer Science & Information Technology G6DICP - Lecture 6 Errors, bugs and debugging.

Slides:



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

Yoshi
Telecooperation/RBG Technische Universität Darmstadt Copyrighted material; for TUD student use only Introduction to Computer Science I Topic 16: Exception.
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.
Slides prepared by Rose Williams, Binghamton University ICS201 Exception Handling University of Hail College of Computer Science and Engineering Department.
2440: 211 Interactive Web Programming JavaScript Fundamentals.
Python Programming Chapter 1: The way of the program Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
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.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
How to Create a Java program CS115 Fall George Koutsogiannakis.
Exceptions in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 4: Enhancing Your Program.
Java Review 2 – Errors, Exceptions, Debugging Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
DEBUGGERS For CS302 Data Structures Course Slides prepared by TALHA OZ (most of the text is from
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 1 Introduction To Computers.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering.
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
Java Programming Exceptions Handling. Topics: Learn about exceptions Try code and catch Exceptions Use the Exception getMessage() method Throw and catch.
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.
Slides Credit Umair Javed LUMS Web Application Development.
Programming Translators.
Jun 16, 2014IAT 2651 Debugging. Dialectical Materialism  Dialectical materialism is a strand of Marxism, synthesizing Hegel's dialectics, which proposes.
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.
ICAPRG301A Week 4Buggy Programming ICAPRG301A Apply introductory programming techniques Program Bugs US Navy Admiral Grace Hopper is often credited with.
1 JavaScript in Context. Server-Side Programming.
Python – Part 1 Python Programming Language 1. What is Python? High-level language Interpreted – easy to test and use interactively Object-oriented Open-source.
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.
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.
Chapter 1 Section 1.1 Introduction to Java Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska Anchorage.
Testing and Debugging Session 9 LBSC 790 / INFM 718B Building the Human-Computer Interface.
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
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.
Making Good Code AKA: So, You Wrote Some Code. Now What? Ray Haggerty July 23, 2015.
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.
Error messages 25-Apr-17.
ERRORS. Types of errors: Syntax errors Logical errors.
Programming Errors. Errors of different types Syntax errors – easiest to fix, found by compiler or interpreter Semantic errors – logic errors, found by.
Debugging 1/6/2016. Debugging 1/6/2016 Debugging  Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a program.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 6: Debugging in MATLAB Monday 15 Sept 2014 EGR 115 Introduction to Computing for Engineers.
Error Handling Tonga Institute of Higher Education.
CS12230 Introduction to Programming Lecture 6-2 –Errors and Exceptions 1.
1 Exceptions. 2 Syntax Errors, Runtime Errors, and Logic Errors syntax errors, runtime errors, and logic errors You learned that there are three categories.
The single most important skill for a computer programmer is problem solving Problem solving means the ability to formulate problems, think creatively.
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
Lecture10 Exception Handling Jaeki Song. Introduction Categories of errors –Compilation error The rules of language have not been followed –Runtime error.
Principles of Programming CSEB134 : BS/ CHAPTER Fundamentals of the C Programming Language.
“Hello World” In Java Mehdi Einali Advanced Programming in Java 1.
The Debugging Process Syntax Errors CPS120 Introduction to Computer Science Lecture 4.
Throw, Throws & Try-Catch Statements Explanations and Pictures from: Reference:
CHAPTER 3 COMPLETING THE PROBLEM- SOLVING PROCESS AND GETTING STARTED WITH C++ An Introduction to Programming with C++ Fifth Edition.
Harvard Mark I Howard Aiken was a pioneer in computing and a creator of conceptual design for IBM in the 1940s. He envisioned an electro-mechanical computing.
Debuggers. Errors in Computer Code Errors in computer programs are commonly known as bugs. Three types of errors in computer programs –Syntax errors –Runtime.
Eighth Lecture Exception Handling in Java
Wrapper Classes Debugging Interlude 1
5.01 Understand Different Types of Programming Errors
CS1101X Programming Methodology
Testing and Debugging.
Software Design and Development
Debugging CMSC 202.
Bugs & Debugging - Testing
PROGRAMMING FUNDAMENTALS Lecture # 03. Programming Language A Programming language used to write computer programs. Its mean of communication between.
An Introduction to Debugging
Review of Previous Lesson
Chapter 15 Debugging.
Chapter 15 Debugging.
Presentation transcript:

School of Computer Science & Information Technology G6DICP - Lecture 6 Errors, bugs and debugging

2 Types of Errors Syntax errors Syntax errors Mistakes in the rules of the language itself Mistakes in the rules of the language itself Illegal Java - errors of grammar or punctuation Illegal Java - errors of grammar or punctuation Semantic errors Semantic errors Mistakes in the logic of the code Mistakes in the logic of the code Legal Java - but not what you intend! Legal Java - but not what you intend!

3 Where errors show themselves Compile-time errors Compile-time errors Many syntax errors are detected by the compiler Many syntax errors are detected by the compiler The compiler will generate an error message - including a line number The compiler will generate an error message - including a line number Run-time errors Run-time errors Some syntax errors are detected by the VM when the program is run Some syntax errors are detected by the VM when the program is run Legal Java - that causes problems under certain conditions. Legal Java - that causes problems under certain conditions. Logical errors Logical errors Unexpected results - bugs! Unexpected results - bugs!

4 Compiler Errors If javac gives no output, the compilation is successful If javac gives no output, the compilation is successful Cannot read… compiler error Cannot read… compiler error This means that the source file (fname.java) has not been read. This means that the source file (fname.java) has not been read. Usually a typo in the file name or javac command Usually a typo in the file name or javac command Remember Java is case sensitive! Remember Java is case sensitive! Could be file privileges Could be file privileges C:\code javac fname.java error: cannot read: fname.java 1 error C:\code

5 Compiler Errors (2) Most compiler errors have a file name and line number Most compiler errors have a file name and line number This tells you where the error was detected This tells you where the error was detected C:\code javac fname.java fname.java:23: cannot resolve symbol symbol : class string location: class fname string msg; ^ 1 error

6 Compiler Errors (cont.) Most compiler errors have a file name and line number Most compiler errors have a file name and line number This tells you where the error was detected This tells you where the error was detected C:\code javac fname.java fname.java:23: cannot resolve symbol symbol : class string location: class fname string msg; ^ 1 error File name (fname.java)

7 Compiler Errors (cont.) Most compiler errors have a file name and line number Most compiler errors have a file name and line number This tells you where the error was detected This tells you where the error was detected C:\code javac fname.java fname.java:23: cannot resolve symbol symbol : class string location: class fname string msg; ^ 1 error Line number (23)

8 Compiler Errors (cont.) Most compiler errors have a file name and line number Most compiler errors have a file name and line number This tells you where the error was detected This tells you where the error was detected C:\code javac fname.java fname.java:23: cannot resolve symbol symbol : class string location: class fname string msg; ^ 1 error Type of error

9 Compiler Errors (cont.) Most compiler errors have a file name and line number Most compiler errors have a file name and line number This tells you where the error was detected This tells you where the error was detected C:\code javac fname.java fname.java:23: cannot resolve symbol symbol : class string location: class fname string msg; ^ 1 error Type of error Details of error

10 Compiler Errors (cont.) Most compiler errors have a file name and line number Most compiler errors have a file name and line number This tells you where the error was detected This tells you where the error was detected C:\code javac fname.java fname.java:23: cannot resolve symbol symbol : class string location: class fname string msg; ^ 1 error Location of error

11 Compiler Errors (3) The point at which the error is detected is not always the point at which there is a mistake in the code The point at which the error is detected is not always the point at which there is a mistake in the code For example unbalanced braces cannot be detected until the braces are closed For example unbalanced braces cannot be detected until the braces are closed Compiler errors can have knock-on effects, with other “spurious” errors being caused by the first Compiler errors can have knock-on effects, with other “spurious” errors being caused by the first ADVICE - fix the first compiler error, and attempt to compile before looking at others - they might disappear! ADVICE - fix the first compiler error, and attempt to compile before looking at others - they might disappear!

12 Runtime Errors Runtime errors occur while the program is running, although the compilation is successful Runtime errors occur while the program is running, although the compilation is successful Usually runtime errors consist of “exceptions” in a thread Usually runtime errors consist of “exceptions” in a thread Errors in the main method, generate exceptions in thread “main” Errors in the main method, generate exceptions in thread “main” NoClassDefFoundError NoClassDefFoundError Caused if the interpreter can’t find the named class file (e.g. fname.class) Caused if the interpreter can’t find the named class file (e.g. fname.class) This is usually a typo - either in the command line, the class declaration or the file name This is usually a typo - either in the command line, the class declaration or the file name Remember Java is case sensitive! Remember Java is case sensitive! Exception in thread "main" java.lang.NoClassDefFoundError: fname

13 Causes of Runtime Errors Errors that only become apparent during the course of execution of the program Errors that only become apparent during the course of execution of the program External Factors - e.g. External Factors - e.g. Out of memory Out of memory Hard disk full Hard disk full Insufficient i/o privileges Insufficient i/o privileges etc. etc. Internal Factors - e.g. Internal Factors - e.g. Arithmetic errors Arithmetic errors Attempts to read beyond the end of a file Attempts to read beyond the end of a file Attempt to open a non-existent file Attempt to open a non-existent file Attempts to read beyond the end of an array Attempts to read beyond the end of an array etc. etc.

14 Exceptions When a potential error condition occurs while a program is running an Exception occurs When a potential error condition occurs while a program is running an Exception occurs For example attempting to read from a non-existent file For example attempting to read from a non-existent file Exceptions are of specific types - e.g. Exceptions are of specific types - e.g. ArithmeticException ArithmeticException IOException IOException ArrayIndexOutOfBoundsException ArrayIndexOutOfBoundsException If the program contains code to handle the exception that code is triggered. If the program contains code to handle the exception that code is triggered. If there is no code to handle the exception then the program terminates with a runtime error If there is no code to handle the exception then the program terminates with a runtime error

15 Missing Class File This can be either a compiler error or a runtime error! This can be either a compiler error or a runtime error! If a class file used by the program is missing at compile time, then a compiler error is generated If a class file used by the program is missing at compile time, then a compiler error is generated If the program is successfully compiled, but a class file is missing when it is run, then a run- time error is generated If the program is successfully compiled, but a class file is missing when it is run, then a run- time error is generated NoClassDefFoundError NoClassDefFoundError

16 Null Pointer Exceptions These are generated if your program atempts to access something non-existent in memory These are generated if your program atempts to access something non-existent in memory Internally these are drastic, but they can be triggered by extremely subtle errors Internally these are drastic, but they can be triggered by extremely subtle errors They do not always provide a line number (or that line might not be where the error is) They do not always provide a line number (or that line might not be where the error is) They can be extremely hard to debug They can be extremely hard to debug

17 Logical Errors The program compiles and runs, but it doesn’t do what is intended The program compiles and runs, but it doesn’t do what is intended May be caused by: May be caused by: Some syntax errors (i.e. legal Java that is wrong in the current context) Some syntax errors (i.e. legal Java that is wrong in the current context) Errors in logical design Errors in logical design These are “bugs” These are “bugs” Term coined by Admiral Grace Hopper for anything that causes a program to do something unexpected Term coined by Admiral Grace Hopper for anything that causes a program to do something unexpected

18 Debugging Paper helps - examine your flow charts Paper helps - examine your flow charts Code tools Code tools Flags - code that tells you where you are in a program Flags - code that tells you where you are in a program Breaks - code that stops the program Breaks - code that stops the program Watches - code that prints the contents of variables Watches - code that prints the contents of variables Debuggers Debuggers Software that implements the above Software that implements the above Also runs code visually in “slow motion” Also runs code visually in “slow motion” Built into most integrated development environments Built into most integrated development environments Invaluable for debugging large, complex programs Invaluable for debugging large, complex programs