The requirements of the following java assignment are unclear to me. Does anyone understand what is needed?
Assignment: In the previous assignment, you implemented a stack and a list that both inherited from the abstract class
ArrayIntCollection. In this next task you are supposed to extend that implementation by making it throw exceptions. If you try to perform operations that are not allowed (for example, if you try to call pop or peek on an empty stack or try to remove an element from a non existing position) you shall create and use the exception classCollectionExceptionof the type UncheckedException. Also write a test programExceptionMain.javathat generates and catches exceptions from your modified methods.
The way I understand it, I need to create an exception class called CollectionException. This class needs to extend UncheckedException. (This part is not working, as I cannot find a class called UncheckedException).
Also, it is apparent whether I am to use try\catch or throw for this task?
Thanks to all!
will mean, yes, you have to use
throw.At least here you will have to use
try...catch.Regarding “UncheckedException”: Either there is a class of this name (perhaps in another package). Then you can ask your teacher where it is. Otherwise you can extend from
java.lang.RuntimeException(which is an unchecked exception) and ask you teacher if that’s OK.