You are on page 1of 3

//1

package codes;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class TestClass {

public void analyze(List<String> data) {

if (data.size() > 50) {


//runtime exception
throw new ListTooLargeException("List can't exceed 50 items!");
}

else
{
throw new ListTooLargeException("List is not exceeded its size!");
}

public static void main(String[] args) {

TestClass obj = new TestClass();

System.out.print("Enter List Size: ");


Scanner scan = new Scanner(System.in);
int a = scan.nextInt();

List<String> data = new ArrayList<>(Collections.nCopies(a, "Test Class"));

obj.analyze(data);

}
}

//2
package codes;

public class ListTooLargeException extends RuntimeException{

public ListTooLargeException(String message) {


super(message);
}

You might also like