java - 澄清java异常赋值中所要求的内容

标签 java exception

我不清楚以下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 class CollectionException of the type UncheckedException. Also write a test program ExceptionMain.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/

相关文章:

java - 如何在调用者的某些条件下更新 Thread 类中变量的值

java - 查找具有最大值的路径,其中 T 平方值可以加倍

C#:GetHashCode、Equals 和 Dictionary 导致 IndexOutOfRangeException?

exception - Jhipster 服务中的异常处理

Java SQL 唯一用户名

java - 复制按字段值分组

java - 将文本文件中转储的文本转换为 Csv 和数组

java - Java 斯坦福图书馆异常

c++ - 如果没有人调用该函数,为什么我会得到 First-chance 异常?

java - 修复打开文件过多异常(我正在使用 try-catch-finally)