{"record":{"id":"dab6fa3e328b8c4a","repo":"TheAlgorithms/Python","slug":"the-queue-is-empty","errorCode":null,"errorMessage":"The queue is empty","messagePattern":"The queue is empty","errorType":"exception","errorClass":"UnderFlowError","httpStatus":null,"severity":"error","filePath":"data_structures/queues/priority_queue_using_list.py","lineNumber":167,"sourceCode":"    def __init__(self):\n        self.queue = []\n\n    def enqueue(self, data: int) -> None:\n        \"\"\"\n        This function enters the element into the queue\n        If the queue is full an Exception is raised saying Over Flow!\n        \"\"\"\n        if len(self.queue) == 100:\n            raise OverFlowError(\"Maximum queue size is 100\")\n        self.queue.append(data)\n\n    def dequeue(self) -> int:\n        \"\"\"\n        Return the highest priority element in FIFO order.\n        If the queue is empty then an under flow exception is raised.\n        \"\"\"\n        if not self.queue:\n            raise UnderFlowError(\"The queue is empty\")\n        else:\n            data = min(self.queue)\n            self.queue.remove(data)\n            return data\n\n    def __str__(self) -> str:\n        \"\"\"\n        Prints all the elements within the Element Priority Queue\n        \"\"\"\n        return str(self.queue)\n\n\ndef fixed_priority_queue():\n    fpq = FixedPriorityQueue()\n    fpq.enqueue(0, 10)\n    fpq.enqueue(1, 70)\n    fpq.enqueue(0, 100)\n    fpq.enqueue(2, 1)","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/data_structures/queues/priority_queue_using_list.py#L149-L185","documentation":"Raised by ElementPriorityQueue.dequeue() (data_structures/queues/priority_queue_using_list.py:167) when self.queue is empty. It uses the module's custom UnderFlowError, mirroring FixedPriorityQueue's underflow behavior. The normal path pops the minimum-valued element (value = priority).","triggerScenarios":"dequeue() on a new ElementPriorityQueue, or after the 100th... after all enqueued elements have been dequeued (list is empty).","commonSituations":"Drain loops (while True: pq.dequeue()), or size checks that race with another consumer of the same queue object.","solutions":["Guard with `if pq.queue:` before calling dequeue()","Catch UnderFlowError imported from data_structures.queues.priority_queue_using_list","Loop with `while len(pq.queue):` so the loop condition and the dequeue share the same state"],"exampleFix":"// before\nsmallest = pq.dequeue()  # UnderFlowError on empty\n\n# after\nsmallest = pq.dequeue() if pq.queue else None","handlingStrategy":"validation","validationCode":"item = pq.dequeue() if pq.queue else None","typeGuard":null,"tryCatchPattern":"from data_structures.queues.priority_queue_using_list import UnderFlowError\ntry:\n    item = pq.dequeue()\nexcept UnderFlowError:\n    item = None","preventionTips":["Use `while pq.queue:` as the drain-loop condition","Do not catch bare Exception expecting queue.Empty — this module uses UnderFlowError"],"tags":["queue","priority-queue","underflow","python"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}