User-defined Exception Class

Learn how to handle the user-defined exceptions in a Queue class.

We'll cover the following

Problem

Write a program that implements a Queue class that throws an exception if we attempt to add a new element to a queue that is already full, or we try to delete an element from a queue that is already empty. Tackle these exceptions in the main( ) function.

Sample run

Here’s what you should see when you run the program.

Added 11
Added 12
Added 13
Added 15

Queue is full

Item deleted = 11
Item deleted = 12
Item deleted = 13
Item deleted = 14
Queue is empty

Coding solution

Here is a solution to the problem above.

Get hands-on with 1400+ tech skills courses.