{"record":{"id":"2623db08476a3b81","repo":"TheAlgorithms/Python","slug":"empty-queue","errorCode":null,"errorMessage":"Empty Queue","messagePattern":"Empty Queue","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"data_structures/queues/circular_queue_linked_list.py","lineNumber":144,"sourceCode":"        Exception: Empty Queue\n        \"\"\"\n        self.check_can_perform_operation()\n        if self.rear is None or self.front is None:\n            return None\n        if self.front == self.rear:\n            data = self.front.data\n            self.front.data = None\n            return data\n\n        old_front = self.front\n        self.front = old_front.next\n        data = old_front.data\n        old_front.data = None\n        return data\n\n    def check_can_perform_operation(self) -> None:\n        if self.is_empty():\n            raise Exception(\"Empty Queue\")\n\n    def check_is_full(self) -> None:\n        if self.rear and self.rear.next == self.front:\n            raise Exception(\"Full Queue\")\n\n\nclass Node:\n    def __init__(self) -> None:\n        self.data: Any | None = None\n        self.next: Node | None = None\n        self.prev: Node | None = None\n\n\nif __name__ == \"__main__\":\n    import doctest\n\n    doctest.testmod()\n","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/data_structures/queues/circular_queue_linked_list.py#L126-L162","documentation":"CircularQueueLinkedList.check_can_perform_operation raises a generic Exception('Empty Queue') when front == rear and front.data is None. It is invoked by first() and dequeue(), making any read or removal on an empty queue fail with this message.","triggerScenarios":"first() or dequeue() on a freshly built CircularQueueLinkedList; dequeuing after all enqueued items were consumed; extra dequeue after a drain loop.","commonSituations":"Peek-before-check patterns; consumers assuming blocking semantics; capacity set to 1 confusing the empty check (front==rear with data None) for a single-slot queue.","solutions":["Call cq.is_empty() before first()/dequeue().","Catch generic Exception and match 'Empty Queue' since no dedicated exception type exists.","In drain loops use 'while not cq.is_empty(): process(cq.dequeue())'."],"exampleFix":"# before\nitem = cq.dequeue()  # Exception: Empty Queue\n# after\nitem = None if cq.is_empty() else cq.dequeue()","handlingStrategy":"validation","validationCode":"item = cq.dequeue() if not cq.is_empty() else None\nfirst = cq.first() if not cq.is_empty() else None","typeGuard":null,"tryCatchPattern":"try:\n    item = cq.dequeue()\nexcept Exception as e:\n    if 'Empty Queue' not in str(e):\n        raise\n    item = None","preventionTips":["first() and dequeue() share this check — guard both with is_empty().","Drain with 'while not cq.is_empty()' loops.","is_empty() requires front==rear AND data None; single occupied slot is not empty."],"tags":["queue","empty-collection","generic-exception","circular-buffer"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}