Modify the exception handling in Java and Python.

This commit is contained in:
krahets
2023-04-23 03:41:39 +08:00
parent 7e59e2c7fb
commit 3590262c7e
14 changed files with 35 additions and 28 deletions

View File

@@ -35,14 +35,14 @@ class ArrayStack {
/* 出栈 */
public int pop() {
if (isEmpty())
throw new EmptyStackException();
throw new IndexOutOfBoundsException();
return stack.remove(size() - 1);
}
/* 访问栈顶元素 */
public int peek() {
if (isEmpty())
throw new EmptyStackException();
throw new IndexOutOfBoundsException();
return stack.get(size() - 1);
}