command line argument and custom exception example in java

WAP to accept 5 command line arguments and then raise custom exception if any argument is not from the list
(“BCA”,”MCA”,”BBA”,”MBA”,”OTHER”).

class CE extends Exception
{
	public CE(String s)
	{
		super(s);
	}
}
class AP17
{
	public static void main(String args[])
	{
		String my_arr[]={"BCA","MCA","BBA","MBA","OTHER"};
		int i,j,flag=0;
		try
		{
			for(i=0;i<5;i++)
			{
				flag=0;
				System.out.println(args[i]);
				for(j=0;j<5;j++)
				{
					if(args[i].equals(my_arr[j]))
					{
						flag=1;
						break;
					}
				}
				if(flag==0)
					throw new CE("=> Not found...");
			}
			System.out.println("Everything is ok");
		}
		catch(CE ex)
		{
			System.out.println(ex.getMessage());
		}
	}
}

Comments

One response to “command line argument and custom exception example in java”

  1. […] WAP to accept 5 command line arguments and then raise custom exceptionif any argument is not from th… […]

Leave a Reply

Your email address will not be published. Required fields are marked *