Contoh Program Throw
Contoh Program Throw
package JOP;
import javax.swing.JOptionPane;
public class tugas_asis {
public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "INI KALKULATOR AKAR");
int bilangan;
double akar;
try{
if(bilangan<0)
throw new ArithmeticException();
akar=Math.sqrt(bilangan);
try{
if(bilangan>=0)
throw new ArithmeticException();
}
catch(ArithmeticException e1){
JOptionPane.showMessageDialog(null, akar,"Nilai Akar",
JOptionPane.INFORMATION_MESSAGE);
}
}
catch(ArithmeticException e){
JOptionPane.showMessageDialog(null, "Bilangan harus lebih dari nol",
"PERINGATAN!!",JOptionPane.WARNING_MESSAGE);
}
finally{
JOptionPane.showMessageDialog(null, "TERIMA KASIH");
}
}
}
Output