What Is Stack Overflow? - Errors, Exceptions & Causes

An error occurred trying to load this video.

Try refreshing the page, or contact customer support.

Coming up next: What is WSDL? - Definition & Example

You're on a roll. Keep up the good work!

Take Quiz Watch Next Lesson
Your next lesson will play in 10 seconds
  • 0:02 Definition of a Stack
  • 1:15 Stack Push & Pop
  • 1:47 Stack Underflow & Overflow
  • 2:33 An Error vs. an Exception
  • 3:52 Causes of Stack Overflow
  • 4:46 Lesson Summary
Save Save Save

Want to watch this again later?

Log in or sign up to add this lesson to a Custom Course.

Log in or Sign up

Speed Speed

Recommended Lessons and Courses for You

Lesson Transcript
Instructor: Lonny Meinecke

Lonny teaches psychology classes at King University, and has a bachelor's degree in IT and a doctorate in psychology.

In this lesson, we'll explore something called stack overflow. We'll examine its definition, see the basics of how a stack works, explain what errors and exceptions are, and list some causes of stack overflow.

Definition of a Stack

In computer programming, a stack is a concept in which we have set aside a location to hold a stack of items, but we can only get to the one on top. The rest of the items are mostly unreachable beneath the top one. We can only get to the top item because a stack is really an abstract structure where the last item you put into it must be removed first in order to reach previous items. We call this last in first out, or LIFO. Computer stacks are really handy because they allow us to reserve temporary storage, so we can pass numbers (or program pointers and program variables, which are a lot like numbers) between program functions (a function does stuff with numbers).

A really good way to visualize a stack is to picture a stack of plates in a cafeteria. You couldn't grab one from the middle very easily, could you? No, when you're standing in line in a cafeteria, you don't want to slow down people behind you, so you grab what's on top. Computer stacks work in pretty much the same way, so programs can run really fast. In essence, items on a stack are removed in reverse order (the last to go in are the first to come out).

Stack Push & Pop

When you add an item (often called an element) to the top of a stack, that's called a push. Push is a good word for this, because the new item pushes all the old ones down. If you've ever worked in a cafeteria or restaurant kitchen, spring-loaded shafts for plates are super common. The weight of the plates on top push the lower plates down.

When you remove an item from a stack, that's called a pop. In a cafeteria, when you remove the topmost plate, the ones beneath it pop up because of the spring beneath them. Well, a computer stack is kind of like that.

Stack Underflow & Overflow

Now that we have a basic picture in mind of what a stack conceptually looks like, we can define what underflow and overflow are. Stack underflow happens when we try to pop (remove) an item from the stack, when nothing is actually there to remove. This will raise an alarm of sorts in the computer because we told it to do something that cannot be done.

Stack overflow happens when we try to push one more item onto our stack than it can actually hold. You see, the stack usually can hold only so much stuff. Typically, we allocate (set aside) where the stack is going to be in memory and how big it can get. So, when we stick too much stuff there or try to remove nothing, we will generate a stack overflow condition or stack underflow condition, respectively.

An Error vs. an Exception

You may think only humans make mistakes, but computers make mistakes all the time (often because humans told them to!). Did you know that the first computer bug wasn't made by a person, it was a real live moth inside a big computer? Nowadays, a computer is on the lookout for bugs, so when a computer has a problem or makes a mistake, it raises some sort of alarm before things get really bad. Generally, we can divide this alarm into two kinds, called errors and exceptions.

An error is an alarm that typically halts further operations. The computer has encountered a problem and doesn't know what to do, so it must be fixed before the computer can resume operation. Either a programmer must debug it, or the user must reboot the computer.

To unlock this lesson you must be a Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use

Become a member and start learning now.
Become a Member  Back
What teachers are saying about
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 200 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create an account