Write a program to input name and salary of employee and throw user defined exception if entered salary is negative.
import java.io.*;
class NegativeSalaryException extends Exception
{
public NegativeSalaryException (String str)
{
super(str);
}
}
public class S1
{
public static void main(String[] args) throws IOException
{
BufferedReaderbr= new BufferedReader(new
InputStreamReader(System.in));
System.out.print("Enter Name of employee");
String name = br.readLine();
System.out.print("Enter Salary of employee");
int salary = Integer.parseInt(br.readLine());
Try
{
if(salary<0)
throw new NegativeSalaryException("Enter Salary amount
isnegative");
System.out.println("Salary is "+salary);
}
catch (NegativeSalaryException a)
{
System.out.println(a);
}
}
}