В моем файле ArrayQueueTest.java я не могу понять, что происходит не так. Я получаю ту же ошибку:
недоступный блок catch для IsEmptyException и IsFullException
Я перепробовал все, от двойной проверки импорта/пакетов, чтобы убедиться, что все имеет правильный путь. У файлов правильный путь. Я подхожу к концу пути с этим заданием, так как понятия не имею, что происходит не так.
package apps;
import adts.ArrayQueue;
import exceptions.IsFullException;
import exceptions.IsEmptyException;
public class ArrayQueueTest {
public static void main(String[] args) {
ArrayQueue queue = new ArrayQueue(3);
try {
queue.enqueue("A");
queue.enqueue("B");
queue.enqueue("C");
System.out.println(queue);
queue.enqueue("D");
}
catch (IsFullException e) {
System.out.println(e.getMessage());
}
catch (IsEmptyException e) {
System.out.println(e.getMessage());
}
try {
System.out.println("Dequeue: " + queue.dequeue());
System.out.println(queue);
queue.dequeue();
queue.dequeue();
queue.dequeue();
}
catch (IsFullException e) {
System.out.println(e.getMessage());
}
catch (IsEmptyException e) {
System.out.println(e.getMessage());
}
}
}
package adts;
import interfaces.QueueInterface;
import exceptions.IsFullException;
import exceptions.IsEmptyException;
public class ArrayQueue implements QueueInterface {
protected E[] queue;
protected int front = 0;
protected int rear = 0;
protected int size = 0;
protected final int DEFAULT_CAPACITY = 5;
@SuppressWarnings("unchecked")
public ArrayQueue() {
queue = (E[]) new Object[DEFAULT_CAPACITY];
}
@SuppressWarnings("unchecked")
public ArrayQueue(int capacity) {
queue = (E[]) new Object[capacity];
}
@Override
public void enqueue(E element) throws IsFullException {
if (isFull()) {
System.out.println("Queue is full, throwing IsFullException"); //
throw new IsFullException("Out, out, brief candle! The queue is ful");
}
queue[rear] = element;
rear = (rear + 1) % queue.length;
size++;
}
@Override
public E dequeue() throws IsEmptyException {
if (isEmpty()) {
System.out.println("Queue is empty, throwing IsEmptyException"); //
throw new IsEmptyException("The queue is empty! All we have is time!");
}
E temp = queue[front];
queue[front] = null;
front = (front + 1) % queue.length;
size--;
return temp;
}
@Override
public boolean isEmpty() {
return size == 0;
}
@Override
public boolean isFull() {
return size == queue.length;
}
@Override
public String toString() {
StringBuilder qStr = new StringBuilder("\nQueue: ");
for (int i = 0; i < size; i++) {
qStr.append(queue[(front + i) % queue.length]).append(" ");
}
return qStr.toString();
}
}
package exceptions;
public class IsEmptyException extends Exception
{
public IsEmptyException(String message)
{
super(message);
}
}
package exceptions;
public class IsFullException extends Exception
{
public IsFullException(String message)
{
super(message);
}
}
package interfaces;
import exceptions.IsEmptyException;
import exceptions.IsFullException;
public interface QueueInterface {
void enqueue(E element) throws IsFullException; // add an element to the queue - always at the end of the queue
E dequeue() throws IsEmptyException; // remove and return the front of the queue
boolean isEmpty();
boolean isFull();
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... e-exceptio
Недостижимый блок Catch для IsEmptyException и IsFullException. Эти исключения никогда не выбрасываются из тела оператор ⇐ JAVA
Программисты JAVA общаются здесь
1729408473
Anonymous
В моем файле ArrayQueueTest.java я не могу понять, что происходит не так. Я получаю ту же ошибку:
недоступный блок catch для IsEmptyException и IsFullException
Я перепробовал все, от двойной проверки импорта/пакетов, чтобы убедиться, что все имеет правильный путь. У файлов правильный путь. Я подхожу к концу пути с этим заданием, так как понятия не имею, что происходит не так.
package apps;
import adts.ArrayQueue;
import exceptions.IsFullException;
import exceptions.IsEmptyException;
public class ArrayQueueTest {
public static void main(String[] args) {
ArrayQueue queue = new ArrayQueue(3);
try {
queue.enqueue("A");
queue.enqueue("B");
queue.enqueue("C");
System.out.println(queue);
queue.enqueue("D");
}
catch (IsFullException e) {
System.out.println(e.getMessage());
}
catch (IsEmptyException e) {
System.out.println(e.getMessage());
}
try {
System.out.println("Dequeue: " + queue.dequeue());
System.out.println(queue);
queue.dequeue();
queue.dequeue();
queue.dequeue();
}
catch (IsFullException e) {
System.out.println(e.getMessage());
}
catch (IsEmptyException e) {
System.out.println(e.getMessage());
}
}
}
package adts;
import interfaces.QueueInterface;
import exceptions.IsFullException;
import exceptions.IsEmptyException;
public class ArrayQueue implements QueueInterface {
protected E[] queue;
protected int front = 0;
protected int rear = 0;
protected int size = 0;
protected final int DEFAULT_CAPACITY = 5;
@SuppressWarnings("unchecked")
public ArrayQueue() {
queue = (E[]) new Object[DEFAULT_CAPACITY];
}
@SuppressWarnings("unchecked")
public ArrayQueue(int capacity) {
queue = (E[]) new Object[capacity];
}
@Override
public void enqueue(E element) throws IsFullException {
if (isFull()) {
System.out.println("Queue is full, throwing IsFullException"); //
throw new IsFullException("Out, out, brief candle! The queue is ful");
}
queue[rear] = element;
rear = (rear + 1) % queue.length;
size++;
}
@Override
public E dequeue() throws IsEmptyException {
if (isEmpty()) {
System.out.println("Queue is empty, throwing IsEmptyException"); //
throw new IsEmptyException("The queue is empty! All we have is time!");
}
E temp = queue[front];
queue[front] = null;
front = (front + 1) % queue.length;
size--;
return temp;
}
@Override
public boolean isEmpty() {
return size == 0;
}
@Override
public boolean isFull() {
return size == queue.length;
}
@Override
public String toString() {
StringBuilder qStr = new StringBuilder("\nQueue: ");
for (int i = 0; i < size; i++) {
qStr.append(queue[(front + i) % queue.length]).append(" ");
}
return qStr.toString();
}
}
package exceptions;
public class IsEmptyException extends Exception
{
public IsEmptyException(String message)
{
super(message);
}
}
package exceptions;
public class IsFullException extends Exception
{
public IsFullException(String message)
{
super(message);
}
}
package interfaces;
import exceptions.IsEmptyException;
import exceptions.IsFullException;
public interface QueueInterface {
void enqueue(E element) throws IsFullException; // add an element to the queue - always at the end of the queue
E dequeue() throws IsEmptyException; // remove and return the front of the queue
boolean isEmpty();
boolean isFull();
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79106510/unreachable-catch-block-for-isemptyexception-and-isfullexception-these-exceptio[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия