Activity 01
Debug It: Find and Fix the Exception
Provide five short code samples, each with a different unhandled runtime exception (NullPointerException, ArrayIndexOutOfBoundsException, NumberFormatException, FileNotFoundException, StackOverflowError). Students individually identify the exception type, explain what triggers it, and add appropriate error handling. Pairs compare their solutions and discuss differences in approach.
Explain the importance of error handling in creating reliable software.
Facilitation TipDuring Debug It, have students work in pairs to trace the stack trace line by line before writing any fixes.
What to look forPresent students with short code snippets in Java or Python that contain common runtime errors (e.g., division by zero, index out of bounds). Ask them to identify the error, predict the output if unhandled, and then write the correct try-catch or try-except block to handle it.