Exceptions throw new RuntimeException(“bad things happened”); The above line is the simplest possible way of throwing an exception. In Java, exceptions.

Slides:



Advertisements
Similar presentations
Exception Handling – illustrated by Java mMIC-SFT November 2003 Anders P. Ravn Aalborg University.
Advertisements

Written by: Dr. JJ Shepherd
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.
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,
CS 106 Introduction to Computer Science I 04 / 11 / 2008 Instructor: Michael Eckmann.
Georgia Institute of Technology Workshop for CS-AP Teachers Chapter 3 Advanced Object-Oriented Concepts.
CS2200 Software Development Lecture: Object class A. O’Riordan, 2008.
CS 106 Introduction to Computer Science I 04 / 16 / 2010 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 11 / 15 / 2006 Instructor: Michael Eckmann.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Objects Real and Java COMP.
Inheritance One of the biggest advantages of object-oriented design is that of inheritance. A class may be derived from another class, the base class.
CIT 590 Missing pieces. Exception handling TryExample2.java in the dropbox folder Shows you how try, catch and finally work together.
1 Object-Oriented Software Engineering CS Interfaces Interfaces are contracts Contracts between software groups Defines how software interacts with.
The Java Inheritance Hierarchy CSIS 3701: Advanced Object Oriented Programming.
Puzzle 3 1  Write the class Enigma, which extends Object, so that the following program prints false: public class Conundrum { public static void main(String[]
Non-static classes Part 2 1. Methods  like constructors, all non-static methods have an implicit parameter named this  for methods, this refers to the.
Object-Oriented Design CSC 212. Announcements This course is speeding up and we are starting new material. Please see me if you feel this is going too.
Some Standard Classes Goals The Object class The String class Wrapper classes The Math class Random Numbers.
Inheritance (Part 2) KomondorBloodHound PureBreedMix Dog Object.
Java for C++ Programmers A Brief Tutorial. Overview Classes and Objects Simple Program Constructors Arrays Strings Inheritance and Interfaces Exceptions.
Scalatest. 2 Test-Driven Development (TDD) TDD is a technique in which you write the tests before you write the code you want to test This seems backward,
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
Written by: Dr. JJ Shepherd
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
Reference Types CSE301 University of Sunderland Harry R Erwin, PhD.
COMP Inheritance and Polymorphism Yi Hong June 09, 2015.
Introduction to Exceptions in Java CS201, SW Development Methods.
9.1 CLASS (STATIC) VARIABLES AND METHODS Defining classes is only one aspect of object-oriented programming. The real power of object-oriented programming.
CS/ENGRD 2110 SPRING 2016 Lecture 6: Consequence of type, casting; function equals 1.
Catie Welsh April 18,  Program 4 due Wed, April 27 th by 11:59pm  Final exam, comprehensive ◦ Friday, May 6th, 12pm  No class Friday - Holiday.
Objects Real and Java COMP T1 3
Inheritance.
Java Exceptions a quick review….
Tirgul 13 Exceptions 1.
CSC 205 Java Programming II
RADE new features via JAVA
Code Magnets problem for wk5
CS/ENGRD 2110 Fall 2017 Lecture 6: Consequence of type, casting; function equals
Software Engineering 1, CS 355 Unit Testing with JUnit
The fattest knight at King Arthur's round table was Sir Cumference
Exceptions C++ Interlude 3
Simple Java I/O part I Using scanner 8-Nov-18.
CS 302 Week 11 Jim Williams, PhD.
Variables as Remote Control
E x c e p t i o n s Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. — Martin Golding.
SWE 332 Last Modified Spring 2010 Paul Ammann
Everything the light touches, Simba, will be yours
CS/ENGRD 2110 Fall 2018 The fattest knight at King Arthur's round table was Sir Cumference. He acquired his size from too much pi. Lecture 6: Consequence.
Testing and debugging A short interlude 2-Dec-18.
Exception Handling Chapter 9 Edited by JJ.
CMSC 202 Exceptions 2nd Lecture.
CMSC 202 Exceptions 2nd Lecture.
Barb Ericson Georgia Institute of Technology Oct 2005
Test Driven Development
CSE 143 Java Exceptions 1/18/2019.
Conditional Logic Presentation Name Course Name
CMSC 202 Exceptions 2nd Lecture.
Testing and debugging A short interlude 17-Apr-19.
CSC 143 Java More on Exceptions.
Test Driven Development
CMPE212 – Reminders Quiz 1 marking done. Assignment 2 due next Friday.
E x c e p t i o n s Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. — Martin Golding.
Exceptions 10-May-19.
LCC 6310 Computation as an Expressive Medium
CMPE212 – Reminders Assignment 2 due next Friday.
Java Basics Exception Handling.
Test-Driven Development
Exception Handling.
CS100J Final Class on Classes 10 February 2005
Exceptions Review Checked Vs. Unchecked Exceptions
Presentation transcript:

Exceptions throw new RuntimeException(“bad things happened”); The above line is the simplest possible way of throwing an exception. In Java, exceptions have a hierarchy. Every type of exception extends a base class called Exception. For this course we do not need you to understand (or for that matter memorize) the types of exceptions. 2

try and catch try { //some code that might throw an exception } catch (SomeSpecificExceptionType e) { // what you want to do in that case // usually after handling the exception you will either // a) e.printStackTrace(); // b) throw(e); See ExceptionHandler.java in JavaExperiments project in Dropbox.

Unit testing What to test first? Pick a function that is independent Write tests for that. Watch tests fail. Write code for that until green bar (for that test). Write a bunch of test cases for this same function and get them to all pass. Pick a function that is either independent or dependent on the set of functions that you have tested. Repeat steps 3 – 7 until all functions are tested. In class – example of unit testing SetOfNames 3

toString, equals Your equals method should not call a toString() method. If both methods are basically doing the same thing, take that common piece of code and put it into its own private method. remember the M word???? Since you want to override these methods you do not have a choice on the method declaration public String toString() {} public boolean equals(Object obj) {}