Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

import javax.swing.

*;
class MyException extends Exception
{
MyException(String msg)
{
super(msg);
}
public static void main(String arg[])
{
int age;
String name="";
try
{
name=JOptionPane.showInputDialog(null,"Name");

age=Integer.parseInt(JOptionPane.showInputDialog(null,"Age"));
if(age<18)
throw (new MyException(" Not Elligible Voter"));
JOptionPane.showMessageDialog(null,name+" Is valid
Voter. Age "+age);
}
catch(MyException e)
{
JOptionPane.showMessageDialog(null,name+e.toString());
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null,e.toString());
}
}
}

You might also like