Cloudera Interview Question

How will you implement a queue with some capacity. If size exceeds capacity throw an exception. Or when you dequeue and queue is empty then throw an exception