Visual Exception Handling Excercise

From Expertiza_Wiki
Jump to navigation Jump to search

The Throw Down

The Problem

Students learn about how thrown exceptions are caught and handled. Exceptions are represented in a real-life set diagram constructed of trays and buckets. Students are given "exceptions" to "handle" by tossing them into the appropriate buckets.

Participants and Props

One class member will participate in the activity at a time. The activity can be performed with a variety of sizes of trays and buckets with large labels. One suggested combination is one large tray, two large buckets, and one small bucket. In this scenario, both large buckets (labeled 'IOException' and 'ClassCastException') sit inside the tray ('Exception'), and one small bucket ('FileNotFoundException') sits inside one of the large buckets ('IOException'). This symbolizes the relationship that IOException and ClassCastException extend Exception, while FileNotFoundException extends IOException. The activity will also require a tennis ball and several cards with code written on them.

Instructions

Students will come up one at a time and each be given a card. The card will contain code which will somehow fail, throwing an exception. The student will then receive the tennis ball. The student will decide which exception the code throws and attempt to 'throw' the tennis ball into the appropriate bucket/bin. If they make the bucket and it is the right exception, they will be awarded one point. The student with the most points at the end of the game wins.

Acknowledgments

This exercise was created by Jason Cockrell and John Phillips