The sample code is:-
import javax.sound.midi.*;
import java.io.*;
class test{
public void go() throws MidiUnavailableException{
//try{
Sequencer sequencer = MidiSystem.getSequencer();
System.out.println("Got it");
//}
/*catch(Exception ex){
System.out.println("Size Matters");
}*/
/*catch(MidiUnavailableException ex){
System.out.println("I am the incorrect exception");
}*/
}
public static void main(String [] args) throws MidiUnavailableException{
test obj = new test();
//try{
obj.go();
//}
/*catch(MidiUnavailableException mex){
System.out.println("Compiler should catch me");
}*/
}
}
I don’t get any while compiling the code; does that mean that JVM will handle the exception in the case? Or if the system is not able to give a sequencer then my program will terminate?
Yes. An unhandled exception will kill the thread. When all non-daemon threads terminate your program will terminate. The exit status is non-zero if the last thread terminated with an exception. And your program has only one thread.