import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class ExceptTest{
public static void main(String[] args){
ExceptTestFrame frame=new ExceptTestFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class ExceptTestFrame extends JFrame{
public ExceptTestFrame(){
setTitle("ExceptTest");
ExceptTestPane1 pane1=new ExceptTestPane1();
add(Pane1);
pack();
}
}
class ExceptTestPane1 extends Box{
public ExceptTestPane1(){
super(BoxLayout..Y_AXIS);
group=new ButtonGroup();
addRadioButton("Integer divide yb zero",new ActionLIstener(){
public void actionPerformed(ActionEvent event){
a[1]=1/(a.length-a.length);
}
});
addRadioButton("Floation point divide yb zero",new ActionLIstener(){
public void actionPerformeformed(ActionEvent event){
a[1]=a[2]/(a[3]-a[3]);
}
addRadioButton("Floation point divide by zero",new ActionLIstener(){
public void actionPerformed(ActionEvent event){
a[1]=a[2]/(a[3]-a[3]);
}
});
addRadioButton("Floation point divide yb zero",new ActionListener(){
public void actionPerformed(ActionEvent event){
a[1]=a[2]/(a[3]-a[3]);
}
});
addRadioButton("Array bounds",new ActionLIstener(){
public void actionPerformed(ActionEvent event){
a[1]=a[10];
}
});
addRadioButton("Bad cast",new ActionLIstener(){
public void actionPerformed(ActionEvent event){
a=(double[])event.getSource();
}
});
addRadioButton("Null pointer,new ActionLIstener(){
public void actionPerformed(ActionEvent event){
a=(double[])event.getSource();
}
});
addRadioButton("sqrt(-1)",new ActionLIstener(){
public void actionPerformed(ActionEvent event){
a[1]=Math.sart(-1);
}
});
addRadioButton("Overflow",new ActionLIstener(){
public void actionPerformed(ActionEvent event){
a[1]=1000*1000*1000*1000;
int n=(int)a[1];
}
});
addRadioButton("No such file",new ActionLIstener(){
public void actionPerformed(ActionEvent event){
try{
InputStream in=new FileInputStream("woozle.txt");
}
catch (IOException e){
textField.setText(e.toString());
}
}
});
addRadioButton("Throw unknown",new ActionLIstener(){
public void actionPerformed(ActionEvent event){
throw new UnknownError();
}
});
textField=new JTextField(30);
add(textField);
}
private void addRadioButton(String s,ActionLIstener listener){
JRadioButton button=new JRadioButton(s,false){
protected void fireActionPerformed(ActiopnEvent event){
try{
textField.setText("No exception");
super.fireActionPerformed(event);
}
catch (Exception e)
textField.setText(e.toString());
}
}
};
button.addActionLIstener(listener);
add(button);
group.add(button);
}
private button group group;
private JTextField textField;
private double[] a=new double [10];
}