Exercises
Let’s deal with some common unhappy path scenarios in our app. When these occur, we need our app to be able to recover from them:
- When reading and writing the dinosaur data, it is possible that the file cannot be opened due to different circumstances. Perhaps someone moved it, it’s in use, or something else. Your task is to simulate a situation where you’re trying to read from a file (that may not exist) and deal with the checked exception.
- While updating dinosaur data, invalid values could sometimes be provided. Write an
updateDinosaurWeight
method that takes a weight value and aDinosaur
object. If the weight value is less than zero, the method should throwIllegalArgumentException
. Use a try-catch block to handle this exception. The handling can be a simpleSystem.out.println
for now. - Even in exceptional circumstances, certain operations should always execute. For example, a daily audit of dinosaurs’ health should happen, whether...