Practice Исключения
This commit is contained in:
+6
-14
@@ -3,21 +3,13 @@ import java.util.ArrayList;
|
|||||||
public class TaskDemo {
|
public class TaskDemo {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
ArrayList<String> card = new ArrayList<>();
|
try {
|
||||||
card.add("Кросовки");
|
// throw new IllegalArgumentException("Неверный формат данных");
|
||||||
card.add("Подписка");
|
} catch (IllegalArgumentException e) {
|
||||||
card.add("Худи");
|
|
||||||
|
|
||||||
card.removeIf(item ->!item.equals("Подписка") );
|
System.out.println("Сработал перехват, Сообщение: " + e.getMessage());
|
||||||
System.out.println(card);
|
} finally {
|
||||||
|
U.pl("Завершение операции");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void cleanCart(String[] card) {
|
|
||||||
for (String item : card) {
|
|
||||||
if (item.equals("Подписка")){
|
|
||||||
U.pl(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user