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?