8 Exceptions


Learning Outcomes



Resources

Exam Topics

  • Handle exceptions using try/catch/finally clauses, try-with-resource, and multi-catch statements

  • Create and use custom exceptions

Oracle Academy

  • 2 Class Design and Exceptions

    • 2-4: Exceptions and Assertions

    • Section 2 Quiz

Textbook


Tutorial / Practice Activity

  • 2-4 Practice: Exceptions and Assertions

Lesson Plan

  • Mindfulness

  • Previous week review

    • write down access code and complete after lesson

    • Repl.it assignment / Canvas assignment

  • Resource reinforcement and clarification

    • Interface vs Abstract classes

  • Polymorphism

  • Components / implications:

    • Base methods can be overriden in derived classes.

    • Overriden method code will be executed even from a call that seems to be from base type. This is dynamic dispatch.

    • A derived type is usable in a context that expects the base type, such as in a collection or as a parameter. This is called subtyping. (More next week.)

  • 2-3

    • Vocabulary

    • Bike toString

  • Project

Mindfulness

public class Animal

{

public void showSpecies()

{

System.out.println("Regular animal");

}

public void makeSound()

{

System.out.println("Grrrrr");

}

}

public class Dog extends Animal

{

public void showSpecies()

{

System.out.println("Dog");

}

public void makeSound()

{

System.out.println("Woof");

}

}

public class Cat extends Animal

{

public void showSpecies()

{

System.out.println("Cat");

}

public void makeSound()

{

System.out.println("Meow");

}

}

public class Program

{

public static void main(String[] args)

{

Cat felix = new Cat();

Dog fido = new Dog();

Animal[] myPets = { felix, fido };

for (Animal anAnimal : myPets)

{

anAnimal.showSpecies();

anAnimal.makeSound();

}

}

}