Exceptions - Introduction to Data Structures - Lecture Notes | COMP SCI 367, Study notes of Data Structures and Algorithms

W3(a) Lecture Notes (Skrentny) Material Type: Notes; Class: Introduction to Data Structures; Subject: COMPUTER SCIENCES; University: University of Wisconsin - Madison; Term: Spring 2014;

Typology: Study notes

2013/2014

Uploaded on 03/11/2014

kmfischer3
kmfischer3 🇺🇸

12 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Copyright 2014 Jim Skrentny CS 367 L5 - 1
CS 367 Announcements
Tuesday, Februar y 4, 2014
Homework 1 due 10 pm Friday, February 7th
Program 1 due 10 pm Sunday, February 16th
Handin directories will be created tomorrow.
Assignment questions? Post on Piazza or see a TA during lab consulting hours.
Last Time
Iterators
concept
iterators and the Java API
using iterators
options for implementing iterators
making a class iterable
Today
Exceptions
throwing
handling
execution
practice with exception handling
Next Time
Exceptions
throws and checked vs. unchecked
defining
Primitive vs Reference Types
ADTs vs. Data Structures
Command Line Execution
Submitting Work
pf3
pf4
pf5
pf8

Partial preview of the text

Download Exceptions - Introduction to Data Structures - Lecture Notes | COMP SCI 367 and more Study notes Data Structures and Algorithms in PDF only on Docsity!

CS 367 Announcements

Tuesday, February 4, 2014

Homework 1 due 10 pm Friday, February 7th

Program 1 due 10 pm Sunday, February 16th

Handin directories will be created tomorrow.

Assignment questions? Post on Piazza or see a TA during lab consulting hours.

Last Time

Iterators

• concept

• iterators and the Java API

• using iterators

• options for implementing iterators

• making a class iterable

Today

Exceptions

• throwing

• handling

• execution

• practice with exception handling

Next Time

Exceptions

• throws and checked vs. unchecked

• defining

Primitive vs Reference Types

ADTs vs. Data Structures

Command Line Execution

Submitting Work

Exception Throwing – Signaling a Problem

Java Syntax

throw exceptionObject ;

Example

Exception Execution

Normal Execution

Exception Execution

ExceptionTester Example

public class ExceptionTester { public static void main (String[] args) { System.out.print("main["); try { methodA( ); System.out.print("after A,"); methodE( ); System.out.print("after E,"); } catch (RedException exc) { System.out.print("red,"); } catch (GreenException exc) { System.out.print("green,"); } finally { System.out.print("finally,"); } System.out.println("]main"); } private static void methodA ( ) { System.out.print("\nA["); try { methodB( ); System.out.print("after B,"); } catch (BlueException exc) { System.out.print("blue,"); } System.out.println("]A"); } private static void methodB ( ) { System.out.print("\nB["); methodC( ); System.out.print("after C,"); try { methodD( ); System.out.print("after D,"); } catch (YellowException exc) { System.out.print("yellow,"); throw new GreenException(); } catch (RedException exc) { System.out.print("red,"); } finally { System.out.print("finally,"); } System.out.println("]B"); }

What is Output When:

5. methodC throws a RedException?

main[ A[ B[

6. methodD throws a RedException?

main[ A[ B[

7. methodD throws a YellowException?

main[ A[ B[

8. methodD throws a OrangeException?

main[ A[ B[

What is Output When:

9. methodC throws a YellowException?

main[ A[ B[

10. methodC throws a BlueException?

main[ A[ B[

11. methodE throws a RedException?

main[ A[ B[