Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Stuff happens. The file isn’t there. The server is down. No matter how good a programmer you are, you can’t control everything. Things can go wrong. Very wrong. When you write a risky method, you need code to handle the bad things that might happen. But how do you know when a method is risky? And where do you put the code to handle the exceptional situation? So far in this book, we haven’t really taken any risks. We’ve certainly had things go wrong at runtime, but the problems were mostly flaws in our own code. Bugs. And those we should fix at development time. No, the problem-handling code we’re talking about here is for code that you can’t guaranatee will work at runtime. Code that expects the file to be in the right directory, the server to be running, or the Thread to stay asleep. And we have to do this now. Because in this chapter, we’re going to build something that uses the risky JavaSound API. We’re going to build a MIDI Music Player.