🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #17221

Re: Throws

#17221
From: Shahid Juma
Date: Thu, 03 Dec 1998 00:00
63 lines
2138 bytes
Okay I did that but have a look at what exactly I did.  I am writing a
function pop().  I am not using Stacks or Vectors, I am using linked
lists.  Basically I have wrote the methods that are used by Stack.

Here it is:

Hello,

    I have done the following

  public Object pop() throws EmptyStackException {
  holdings = tempo.data;
       if (top.get_next() == null) {
           top = null;
           tempo = null;
           temp = null;
       throw new EmptyStackException();
       }

  else {
           tempo = tempo.get_next();
           top.set_next(null);
           top = tempo;
    }
       return holdings;

   }

 This doen't seem to work, it says the following:

java.lang.NullPointerException
        at LinkedStack.pop(Compiled Code)
        at LinkedStack.pop(Compiled Code)
        at Assignment4.interactiveTest(Compiled Code)
        at Assignment4.main(Assignment4.java:31)

Is anything wrong anywhere?

Thanks
Shahid



Steve Schafer (TeamB) wrote:

> On Thu, 03 Dec 1998 12:54:00 -0800, Shahid Juma <shahidj@interlog.com>
> wrote:
>
> >    How do you throw an exception such as EmptyStackException?  Do you
> >do something like this:
> >
> >public Object test (Object d) throws EmptyStackException {
> >}
> >
> >I tried that and it doesn't do it.
>
> That declaration tells the compiler that the test method is _capable_
> of throwing an exception. To actually throw the exception somewhere
> within the body of the method:
>
>  throw new EmptyStackException();
>
> -Steve
Technical Details
Message-ID: <366732FB.D0235A7F@interlog.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3666FA68.1AE15DBC@interlog.com> <3732fbbd.825410610@90.0.0.40>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,32517523289d282
X-Google-Attributes: gidf74b3,public
From: Shahid Juma <shahidj@interlog.com>
Subject: Re: Throws
Date: 1998/12/03
Message-ID: <366732FB.D0235A7F@interlog.com>
X-Deja-AN: 418383005
Content-Transfer-Encoding: 7bit
References: <3666FA68.1AE15DBC@interlog.com> <3732fbbd.825410610@90.0.0.40>
To: pandeng@telepath.com
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language