Need to create a new RunTimeException for EmptyStacks

后端 未结 3 838
不思量自难忘°
不思量自难忘° 2021-01-05 00:38

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

3条回答
  •  天命终不由人
    2021-01-05 00:57

    Create a new runtime exception type called EmptyStackException.

    create type is done by

    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);
          }
        }
    

提交回复
热议问题