Software Development Handing Errors and Creating Documentation

Slides:



Advertisements
Similar presentations
Chapter 17 Failures and exceptions. This chapter discusses n Failure. n The meaning of system failure. n Causes of failure. n Handling failure. n Exception.
Advertisements

Pearson Education, Inc. All rights reserved. 1.. Exception Handling.
Exceptions CSE301 University of Sunderland Harry Erwin, PhD.
Chapter 8 Improving the User Interface
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.
 Both System.out and System.err are streams—a sequence of bytes.  System.out (the standard output stream) displays output  System.err (the standard.
Exceptions1 Syntax, semantics, and pragmatics. Exceptions2 Syntax, semantics, pragmatics Syntax –How it looks, i.e. how we have to program to satisfy.
Slides prepared by Rose Williams, Binghamton University ICS201 Exception Handling University of Hail College of Computer Science and Engineering Department.
Exceptions1 Syntax, semantics, and pragmatics. Exceptions2 Syntax, semantics, pragmatics Syntax –How it looks, i.e. how we have to program to satisfy.
Exceptions Briana B. Morrison CSE 1302C Spring 2010.
Chapter 10 Introduction to Arrays
Utilities (Part 3) Implementing static features 1.
Object-Oriented Enterprise Application Development Javadoc Last Updated: 06/30/2001.
Scott Grissom, copyright 2004Ch 3: Java Features Slide 1 Why Java? It is object-oriented provides many ready to use classes platform independent modern.
Chapter 11: Handling Exceptions and Events J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Fourth.
Chapter 10 Classes Continued
Fall 2007CS 225 Program Correctness and Efficiency Chapter 2.
1 Documenting with Javadoc CS 3331 Fall 2009 How to Write Doc Comments for the Javadoc TM Tool available from java.sun.com.
Writing JavaDocs Mimi Opkins CECS 274 Copyright (c) Pearson All rights reserved.
Contract based programming Using pre- and post-conditions, and object invariants Contract based programming1.
Program documentation using the Javadoc tool 1 Program documentation Using the Javadoc tool.
1 Documenting with Javadoc. 2 Motivation  Why document programs? To make it easy to understand, e.g., for reuse and maintenance  What to document? Interface:
Java Programming: Guided Learning with Early Objects
Exceptions Handling Exceptionally Sticky Problems.
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.
Javadoc Comments.  Java API has a documentation tool called javadoc  The javadoc tool is used on the source code embedded with javadoc-style comments.
Software Documentation Section 5.5 ALBING’s Section JIA’s Appendix B JIA’s.
Data Structures Using Java1 Chapter 2 Inheritance and Exception Handling.
Chapter 12 Handling Exceptions and Events. Chapter Objectives Learn what an exception is Become aware of the hierarchy of exception classes Learn about.
Javadoc A very short tutorial. What is it A program that automatically generates documentation of your Java classes in a standard format For each X.java.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 11 Handling Exceptions and Events.
Page 1 – Autumn 2009Steffen Vissing Andersen SDJ I1, Autumn 2009 Agenda: Java API Documentation Code Documenting (in javadoc format) Debugging.
Computer Science 209 Software Development Handing Errors and Creating Documentation.
Java Doc Guideline R.SANTHANA GOPALAN. Java Doc Guideline Audience Internal Developers PQA - who write test plans PPT – who write the documentation Customers.
1 Documenting with Javadoc CS 3331 Section and Appendix B of [Jia03] How to Write Doc Comments for the Javadoc TM Tool available from
Exceptions Handling Prepared by: Ligemm Mae del Castillo.
Documentation Javadocs. Design/Documentation An essential ingredient of good Object Oriented programming is known as design by contract. This means that.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 10: Programming Exceptionally.
Effective Java, Chapter 9: Exceptions Items Last modified Fall 2012 Paul Ammann.
1 Documenting with Javadoc How to Write Doc Comments for the Javadoc TM Tool available from java.sun.com.
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.
Variable Scope & Lifetime
CMSC202 Computer Science II for Majors Lecture 16 – Exceptions
More Sophisticated Behavior
Exceptions In this lecture:
Handling Exceptionally Sticky Problems
Software Development Java Classes and Methods
Introduction to Exceptions in Java
Introduction to javadoc
Design by Contract Fall 2016 Version.
Exception Handling Chapter 9.
Defining New Types of Objects, part 3
Effective Java, 3rd Edition Chapter 10: Exceptions
CSE 143 Java Exceptions 1/18/2019.
Chapter 12: Exceptions and Advanced File I/O
Lecture 11 Objectives Learn what an exception is.
Introduction to javadoc
Go to pollev.com/cse143.
Java Programming Exceptions CSC 444 By Ralph B. Bisland, Jr.
SWE 619 Last modified Fall 2007 Saket Kaushik, Paul Ammann
Handling Exceptionally Sticky Problems
Effective Java, Chapter 9: Exceptions
Computer Science 340 Software Design & Testing
Building Java Programs Appendix B
Java Programming: From Problem Analysis to Program Design, 4e
Design Contracts and Errors A Software Development Strategy
Presentation transcript:

Software Development Handing Errors and Creating Documentation Computer Science 209 Software Development Handing Errors and Creating Documentation

Error Handling: Who Is Responsible? The client (ultimately, the human user) The server (ultimately, the programmer of the basic software components)

Example Errors Invalid data used to create a Student object (negative numbers, etc.) The position is out of range during the retrieval or replacement of a student’s test score A stack is empty before a pop

Handling Errors, v1 A method returns true to indicate success or false to indicate failure Works well when there is only one kind of error and no other value must be returned The client checks the return value and takes action if necessary

Handling Errors, v2 A method returns null to indicate success or a string to indicate failure The string is also a message indicating the type of error (good for 2 or more types of errors) The client checks the return value and takes action if necessary

Handling Errors, v3 When Java detects an error at run time, an exception is thrown For example, when a program attempts to divide by zero, Java throws an ArithmeticException This method guarantees that errors are detected

Example: Divide by 0 int dividend = 15; int divisor = 0; System.out.println("The quotient is " + dividend / divisor); Java throws an exception and the JVM halts with an error message: A new instance of ArithmeticException is created. This object contains the error message that is displayed in the terminal window.

Example: Divide by 0 int dividend = 15; int divisor = 0; System.out.println("The quotient is " + dividend / divisor);

Example: Index Out of Bounds public int getScore(int i){ return scores[i – 1]; } An ArrayIndexOutOfBoundsException is thrown if i < 1 or i > scores.length

Throwing Your Own Exception public int getScore(int i){ if (i < 1 || i > scores.length) throw new IllegalArgumentException("i must be between " + "1 and " + scores.length); return scores[i – 1]; } Throw an exception of the appropriate type Java’s hierarchy of exception classes is listed in Oracle’s documentation, under Exception Summary in java.lang

Error Conditions Requiring Exceptions A class’s interface gives the client enough information to use a class To use a class properly, the client must be aware of possible error conditions These conditions are specified by placing preconditions and postconditions in the interface

The Interface Is a Contract Between Client and Server Preconditions - state what must be true before a method is run to produce the expected results Postconditions - state what the expected results are when the preconditions are satisfied

Guidelines for Error Handling Servers: Methods should enforce preconditions by throwing exceptions Clients: There is no need to worry about potential exceptions if you obey the preconditions first Some methods require exceptions to be caught (more on this when we examine I/O)

When You Don’t Know the Type public int getScore(int i){ if (i < 1 || i >= scores.length) throw new RuntimeException("i must be between " + "1 and " + scores.length); return scores[i – 1]; }

javadoc Java includes a tool, javadoc, and a special notation for program comments that allow you to generate Web-based documentation These comments highlight parameters, returned values, and possible exceptions for methods, as well as prefatory info on the class

Syntax of Javadoc Comments /** * text * goes * here */ Use /** to begin the comment and * at the beginning of each line.

Documenting the Class /** * A <code>Student</code> object represents a name and a set of * test scores for a student.. * @author Ken Lambert * @author Martin Osborne * @version 1.0 */ class Student extends Object implements Comparable<Student>{ // Blah blah blah } The @ symbol is a prefix for specialized comment tags

Documenting a Method /** * Returns the score at the specified position. * @param i - the position of the score * @return the score * @throws IllegalArgumentException if i less than 1 or i greater than * number of scores */ public int getScore(int i)

Running javadoc > javadoc *.java This will create Web pages for all of the classes in the current working directory There are many options as well

Packages Easy GUIs with BreezySwing For Wednesday Packages Easy GUIs with BreezySwing