Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Seeking advice on EmptyStackException()

  1. #1
    Junior Member
    Join Date
    May 2023
    Posts
    7
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Seeking advice on EmptyStackException()

    Hello, Java noob here! I say noob, I first started with Java 1 with v1.0 in 1996, but then went with Delphi instead. Now circumstances have led me to tackle Java again, because I need to program extension modules for the Bitwig Studio music application. So, I am effectively a noob again, albeit one with easier access to learning material!

    I have a situation where, in normal circumstances, I would expect a Stack object to be empty, but would like to throw an exception if it is not. Is there an inverse to the EmptyStackException(), a NonEmptyStackException() if you like? I can get round the problem, but studying Java again has reawakened the desire to be semantically pure(ish) wherever possible 😉

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Seeking advice on EmptyStackException()

    You can write your own class if there isn't one in the standard Java API
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    May 2023
    Posts
    7
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Seeking advice on EmptyStackException()

    I was wondering about that. Presumably I just extend from the `RuntimeException` class...

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Seeking advice on EmptyStackException()

    Yes that sounds right. You could look at the EmptyStackException class and model it after that.
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    carlcaulkett (May 10th, 2023)

Similar Threads

  1. [SOLVED] Seeking for better algo
    By dicdic in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 7th, 2013, 04:07 AM
  2. seeking who will help
    By Zakariya Kumba in forum Member Introductions
    Replies: 0
    Last Post: November 9th, 2012, 09:29 PM
  3. Seeking help with a program.
    By Gravs2889 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 15th, 2012, 07:51 AM
  4. confused and seeking advice
    By mrgreaper in forum Java Theory & Questions
    Replies: 11
    Last Post: January 1st, 2011, 07:10 AM

Tags for this Thread