需要为EmptyStacks创建一个新的RunTimeException [英] Need to create a new RunTimeException for EmptyStacks

查看:86
本文介绍了需要为EmptyStacks创建一个新的RunTimeException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我的任务可能听起来很简单,但令我难以置信。
我已经浏览了互联网上的代码,但我无法掌握。我也不能用b $ b来掌握老师发布的幻灯片。这就是我所要求的。

So my task may sound simple, but it has me boggled. I have looked through code on the internet, but I cannot get to grips with. Neither can I get to grips with the slides my teacher posted. This is what is required from me.

创建一个名为EmptyStackException的新运行时异常类型。

Create a new runtime exception type called EmptyStackException.

但是我有不知道如何制作方法,类,变量或任何需要制作的东西以满足要求。
我有一些类是DynamicArrayStack和LinkedStack的实现。 Stack的接口。

However I have no clue how to make the method, class, variable or whatever needs to be made in order to fulfill the requirement. I have a few classes that are implementations of a DynamicArrayStack and a LinkedStack. An interface for Stack.

任何指针都会非常有用。

Any pointers would be mightily helpful.

谢谢

Mjall2

推荐答案

创建一个名为EmptyStackException的新运行时异常类型。

创建类型由

public class EmptyStackException extends RuntimeException { ... }

现在,如果我们知道要放入这种新类型(也就是类)的内容。
通常我们会查看超类中的方法并覆盖那些需要不同处理的方法。下面我已经覆盖了其中的一些,但委托回现有的课程。如果您不需要对行为进行任何更改,则无需执行此操作。

Now if only we knew what to put in this new type (a.k.a. class). Typically we look at the methods in the superclass and override those needing different handling. Below I have overridden some of them but delegated back to the existing class. No need to do this if you don't need to make any changes in behavior.

public class EmptyStackException extends RuntimeException {
      public EmptyStackException() {
          super();
      }
      public EmptyStackException(String s) {
          super(s);
      }
      public EmptyStackException(String s, Throwable throwable) {
          super(s, throwable);
      }
      public EmptyStackException(Throwable throwable) {
          super(throwable);
      }
    }

这篇关于需要为EmptyStacks创建一个新的RunTimeException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆