Chapter 9. Exceptions and Message Boxes: Get the message?

image with no caption

Sometimes things just go wrong. You just need to handle it.

There will always be things beyond your control. Networks will fail. Files will disappear. Smart coders learn how to deal with those kinds of errors and make their programs recover gracefully. The best software keeps the user informed about the bad things that happen and what should be done to recover. By learning how to use exceptions and message boxes, you can take your software to the next level of reliability and quality.

What’s that smell?

Just when it looked like things were going so well, there was a problem in the Head-Ex storeroom.

image with no caption

A trainee was recording the consignment of cheese when there was a problem that prevented the program from recording the delivery. That meant the cheese was never assigned to a delivery truck. So the cheese never left the storeroom and it just sat there for a very long time. And that meant—well, you can just imagine...

To prevent the same thing happening again, you need to find what caused the problem.

Someone changed the file permissions

It turns out the whole thing was caused when someone from Technical Support decided to change the permissions on the deliveries.txt file, making it read-only. When the system tried to write deliveries into ...

Get Head First Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.