0

Hey, im getting the following error

unreported exception Exceptions.IllegalValue; must be caught or declared to be thrown

this is my method where im getting the error and i want to know why im getting this error because i declared that the exception was to be thrown.
is it something to do with my if and else statements and where the brackets are located??

any suggestions greatly appreciated :)

/**
	 * adds an object to the front of the queue
	 * @param Object e, int p the object to add and the priority respectively
	 * @exception IllegalValue if the priority number is less than 0
	 */
	public void enqueue(Object e, int p) throws IllegalValue{ 
		if(p > 0)	{
			Iterator it = this.iterator();
			if (isEmpty() || p > front.priority) {
				front = new Link(e,p,front);
			} else {
				Link temp = (Link)it.next();
				while (it.hasNext() && temp.priority >= p) {
					it.next();
				}
					temp = new Link(e,p,temp);
			}
		}else throw new IllegalValue("illegal priority value");
		
	}
2
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by becdudek
0

it's referring to the method that calls it in my test file

q.enqueue(Integer.valueOf(1),1);

0

well i mean it happens when i try to compile my test code and not my code where that method is located

0

So there's nothing wrong with your method.
When you call a method that says it "throws IllegalValue", the calling method must either catch that exception or declare that it too will throw it up to whatever called it.

0

ah cool cheers yeh i changed the test file and now it works, thankyou!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.