In my use case, I am looping across a map and checking whether a particular key is present in a list. If it is present then I have to trow and exception otherwise continue with the execution.
Map<A,B> myMap = new HashMap<A,B>(); //code to populate values in myMap ... ... List<A> myList = new ArrayList<A>(); //code to populate values in myList ... ... for(Map.Entry<A,B> eachElementInMap:myMap.entrySet()){ if(myList.contains(eachElementInMap:myMap.getKey())){ //throwing exception throw new MyCustomizedException("someString"); } } //code continues ... .... In the above example, if there are 3 elements in the map(myMap) in which 1 key is present in the list(myList), I want to throw the exception for one and it should continue executing other lines of code for the rest two. Am I using a wrong design to achieve this? Any help or suggestion is appreciated! Thanks
Exceptions/errors/whateverand return that to the calling method