Error Handling Tonga Institute of Higher Education.

Slides:



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

P5, M1, D1.
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
Exception Handling Chapter 15 2 What You Will Learn Use try, throw, catch to watch for indicate exceptions handle How to process exceptions and failures.
An Introduction to Java Programming and Object- Oriented Application Development Chapter 8 Exceptions and Assertions.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 13 Exception Handling.
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.
1 Lecture 11 Interfaces and Exception Handling from Chapters 9 and 10.
Microsoft VB 2005: Reloaded, Advanced Chapter 5 Input Validation, Error Handling, and Exception Handling.
A Review. a review of lessons learned so far… ( 2 steps forward - 1 step back) Software Development Cycle: design, implement, test, debug, document Large.
Java Programming, 3e Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
© The McGraw-Hill Companies, 2006 Chapter 9 Software quality.
Exceptions in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Java Review 2 – Errors, Exceptions, Debugging Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
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.
Object Oriented Programming
Java Programming Exceptions Handling. Topics: Learn about exceptions Try code and catch Exceptions Use the Exception getMessage() method Throw and catch.
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.
Slides Credit Umair Javed LUMS Web Application Development.
Coding Methodology How to Design Code. © 2005 MIT-Africa Internet Technology Initiative Pay Attention to Detail When implementing or using APIs details.
The Java Programming Language
2_Testing Testing techniques. Testing Crucial stage in the software development process. Significant portion of your time on testing for each programming.
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.
COMP Exception Handling Yi Hong June 10, 2015.
Object Oriented Software Development 8. Exceptions, testing and debugging.
Introduction to Exception Handling and Defensive Programming.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
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.
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.
BIO Java 1 Exception Handling Aborting program not always a good idea – can’t lose messages – E-commerce: must ensure correct handling of private.
Exceptions cs1043. Program Exceptions When a program detects an error, what should it do? – Nothing, simply allow the program to fail. – Implement a course.
MCS 270 Spring 2014 Object-Oriented Software Development.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
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.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
1 Program Planning and Design Important stages before actual program is written.
Sheet 3 HANDLING EXCEPTIONS Advanced Programming using Java By Nora Alaqeel.
Java Programming, 2E Introductory Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 11 Handling Exceptions and Events.
Exceptions Chapter 16 This chapter explains: What as exception is Why they are useful Java exception facilities.
School of Computer Science & Information Technology G6DICP - Lecture 6 Errors, bugs and debugging.
Exceptions and Assertions Chapter 15 – CSCI 1302.
Exceptions in Java. What is an exception? An exception is an error condition that changes the normal flow of control in a program Exceptions in Java separates.
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.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
1 Exceptions. 2 Syntax Errors, Runtime Errors, and Logic Errors syntax errors, runtime errors, and logic errors You learned that there are three categories.
Java Programming: Exceptions1 Exceptions Reference: java.sun.com/docs/books/tutorial/essential/exceptions/
Exceptions Lecture 11 COMP 401, Fall /25/2014.
Compiler Errors Syntax error Lexical Can not resolve/find symbol Can not be applied Execution error Oh wait, a run time error Intent error It ran, but.
ECE122 L23: Exceptions December 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 24 Exceptions.
Introduction to Exceptions in Java CS201, SW Development Methods.
EXCEPTIONS. Catching exceptions Whenever a runtime error occurs, it create an exception object. The program stops running at this point and Python prints.
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.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Enhanced Car Payment Calculator Application Introducing Exception Handling.
16 Exception Handling.
Testing and Debugging.
Chapter 12 Exception Handling and Text IO
Tonga Institute of Higher Education
Lecture 11 Objectives Learn what an exception is.
Problems Debugging is fine and dandy, but remember we divided problems into compile-time problems and runtime problems? Debugging only copes with the former.
PROGRAMMING FUNDAMENTALS Lecture # 03. Programming Language A Programming language used to write computer programs. Its mean of communication between.
Errors and Exceptions Error Errors are the wrongs that can make a program to go wrong. An error may produce an incorrect output or may terminate the execution.
Java Programming: From Problem Analysis to Program Design, 4e
Presentation transcript:

Error Handling Tonga Institute of Higher Education

Fixing Errors Bug – An error in a program. Debug - To find and remove errors (bugs) from a software program. Read the error! Use the task list to quickly take you to the source of your error. Try to fix the error yourself before asking for help. If you ask for help, be able to describe what's going on. The more experience you have with errors, the better you will be able to fix them in the future.

Compile Errors, Runtime Errors and Logical Errors Compile Errors – Errors that are found during the compilation of a program  Your program is unable to compile Runtime Errors – Errors that cause an abnormal termination of a program  Your program crashes Logical Errors – Errors that are not found during the compilation of a program and do not cause an abnormal termination of the program  These are the most difficult to find and often result in very big problems.  You set an employees pay check to be $500,000 instead of $50,000

Common Compile Errors Java is Case Sensitive  Any class, method or variable name must be written exactly the same.  Error Message: cannot resolve symbol  Symbol – A class, method or variable name A semicolon is required at the end of every statement  Error Message: ’;’ expected Brackets and Parenthesis must occur in matching pairs  Every time we open a bracket or parenthesis, we need to close it.  Error Message: ‘}’ expected ‘)’ expected

Common Compile Errors Parenthesis must surround the condition in an IF Statement  Error Message: ‘(’ expected Must Initialize a Variable before using it  Error Message: Variable might not have been initialized Must specify a return type for each method  Error Message: Invalid method declaration; return type required A method that returns something must have a return value specified.  Error Message: Missing return statement

Common Compile Errors A method that returns something must return the correct type  Error Message: Incompatible types A method that doesn’t return anything must not use the return keyword  Error Message: Cannot return a value from method whose result type is void Creating an overloaded method with the same signature  is already defined in

Common Runtime Errors The Equality Operator (==) is different from the Assignment Operator (=)  The IF Statement will not function properly Not calling System.Exit(0);  This is required to exit a graphical user interface Not providing a way for Loops to end  The program will run forever Not including a Break statement in a Switch statement  Undesired code will be run Dividing a number by 0  Error Message: java.lang.ArithmeticException: / by zero

Java Error Handling Java can gracefully handle runtime errors Things you may want to do in your error handling  Display an error message  Allow user to contact technical support  Allow user to send error data to creator of software  Save data  Release any resources that are being used

Exceptions Exception – An error that occurred that can be handled by Java An exception is a class When an exception occurs, we can do 2 things: 1. Ignore the exception 2. Handle the exception Use Try/Catch/Finally structure

Try/Catch/Finally Structure Use the Try/Catch/Finally structure to handle exceptions  You can catch all exceptions or a particular type of an exception  The finally structure is optional try { //Code that may cause an exception } catch ( ) { //Code that handles the exception } finally { //Code to always run after the try or catch code is run }

Try/Catch/Finally Statement - 1 Code you are trying

Demonstration Try/Catch/Finally 1

Try/Catch/Finally Statement - 2 Code you are trying Catches specific exception Catches general exceptions

Demonstration Try/Catch/Finally 2