Q:

try-catch not working properly

I'm reading Java from HeadFirst. I started reading the chapter about Exception Handling. There was code in the book that I executed on my computer.
import javax.sound.midi.*;
class PlayMusic
{
    public void play()
    {
        try{
            Sequencer sq = MidiSystem.getSequencer();
            System.out.println("We got a sequencer");
        }
        catch(MidiUnavailableException ex)
        {   
            System.out.println("Bummer!");  
            ex.printStackTrace();
        }
    }
    public static void main(String[] args)
    {
        PlayMusic pm = new PlayMusic();
        pm.play();
    }
}

When I remove the try-catch block, the compiler raises a MidiUnavailableException error. I used try-catch to catch that exception, but System.out.println("Bummer"); doesn't get executed. Instead, the try block is executed.
What is happening here?

A:

MidiUnavailableException is a checked exception, so you are required to include the catch block in order for the code to compile.  However, there is no guarantee that the exception will actually be thrown when your program executes.  In your case, it isn't being thrown, so the code in your try block executes normally and your printout for the error never gets called.

