我不清楚以下java作业的要求。有谁明白需要什么吗?
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 classCollectionException
of the type UncheckedException. Also write a test programExceptionMain.java
that generates and catches exceptions from your modified methods.
按照我的理解,我需要创建一个名为 CollectionException
的异常类。该类需要扩展UncheckedException
。 (这部分不起作用,因为我找不到名为 UncheckedException
的类)。
此外,很明显我是否要使用 try\catch
还是 throw
来完成此任务?
谢谢大家!
最佳答案
...by make it throw exceptions...
意味着,是的,你必须使用抛出
。
Also write a test program ExceptionMain.java that generates and catches exceptions from your modified methods.
至少在这里你必须使用try...catch
。
关于“UncheckedException”:要么存在一个同名的类(可能在另一个包中)。然后你可以问你的老师它在哪里。否则,您可以从java.lang.RuntimeException
(这是一个未经检查的异常)进行扩展,并向老师询问是否可以。
关于java - 澄清java异常赋值中所要求的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9377742/