Class EmptyStackException in Java

Class EmptyStackException in Java

EmptyStackException is thrown by the Stack class to indicate that the stack is empty and there is no element present to pop out from the stack. A stack is based on LIFO technique ( Last In First Out). Given peek() method on an empty stack can throw this exception.

EmptyStackException is caused by empty() and pop() methods of the stack class and system. currentTimeMillis
() of Date class.

All implemented interfaces- serializable.

The hierarchy of EmptyStackException

Class EmptyStackException in Java
Class EmptyStackException in Java
  • lang.Object
  • -lang.Throwable
  • –lang.Exception
  •  —lang.RuntimeException
  • ——util.EmptyStackException

The structure of EmptyStackException is given by

public class java.util.EmptyStackException extends java.lang.RuntimeExceprion{
public EmptyStackException();
//constructs a new EmptyStackException with no details message.


The class EmptyStackException also inherits methods from class Object and Throwable.

From Object classFrom Throwable class
clone()-this method creates a copy of the given objectfillInStackTrace()-this function fills the program stack with exception traces.
getClass()-this method returns the class name of the object.getMessage()-this function returns the details message of the exception
notify()-this method wakes up another thread that was waiting on this object’s monitor.printStackTrace()- this method prints the throwable and can back trace the information on standard error stream.
wait()printStackTrace(PrintWriter)-this method prints the throwable to the given printwriter
wait(long, int)getLocalizedMessage()-this function creates localized description of this throwable
wait(long)printStackTrace(PrintStream)-this method prints the throwable to the given printstream
equals(Object)-this method checks if the other object is equals is to this object.addSuppressed()- this function appends the suppressed and specified exception.
finalize()-this method keeps in garbage collectiongetCause()-this function returns the cause of the specific throwable an else return null if no cause found.
hashCode()-this method returns the hashCode of the objectgetStackTrace()-this methods provides a programmatic access to the stack information provided by getSuppressed() and printStackTrace() method
notifyAll()- This method wakes up all threads that was waiting on this objects monitor.getSuppressed()
initCause()-this method initializes the throwable to a specified value
setStackTrace()- this method sets the stack trace elements got from getStackTrace() or printed by printStackTrace() .
toString()-this method returns a string representation of the throwable.
throwable()-It returns all of the suppressed exceptions in an array
See also  How To Automate JNLP Based Swing Application In Java

Share and Enjoy !

Leave a Reply

Your email address will not be published. Required fields are marked *