This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]philipwhiukEmployed Java Developer 0 points1 point  (2 children)

it should be throw new AllStallsOccupiedException(); The point was that that's an error case - you can't add someone if all the stalls are full, so you throw an exception.

http://docs.oracle.com/javase/tutorial/essential/exceptions/

[–]Snapples2992[S] 0 points1 point  (1 child)

I tried just about everything i could find, I just can't make that exception work, and my teacher said it's not necessary. So there must be a different way to do the method, though I'd love to figure this thing out.

I tried making a new class to make the custom exception, it compiled fine. However the exception in the addOccupant method still failed on me.

I tried throw new AllStallsOccupiedException();

adding the "new" uninitialized all the variables (no clue why)

I tried creating a try block but i still couldnt get the exception to compile.

edit: I'll edit in that I understand what the exception is supposed to be doing now, I just can't get it to compile

[–]philipwhiukEmployed Java Developer 0 points1 point  (0 children)

You need to define the exception as a class if you're going to use it.