Java

James Ashdown
James Ashdown
13,660 Points

Why are we catching exceptions for the fill method in Example.java and not within the fill method in PezDispenser.java?

Just wondering why we aren't catching the exception where it is actually happening.

1 Answer

KRIS NIKOLAISEN
KRIS NIKOLAISEN
54,333 Points

This allows the code that uses the PezDispenser class to decide how the exception should be handled - maybe you want to print an error message to the screen, maybe you want to do something else. If it were handled inside the PezDispenser class you'd be stuck with whatever was coded there.