S
ssecorp
Is this correct use of exceptions? to raise an indexerror and add my
own string insetad of just letting it raise a IndexError by itself and
"blaming" it on list.pop?
class Stack(object):
def __init__(self, *items):
self.stack = list(items)
def push(self, item):
self.stack.append(item)
def pop(self):
try:
return self.stack.pop()
except:
raise IndexError, "pop from empty stack"
class Queue(object):
def __init__(self, *items):
self.queue = list(items)
def append(self, item):
self.queue.append(item)
def pop(self):
try:
return self.queue.pop(0)
except:
raise IndexError, "pop from empty queue"
own string insetad of just letting it raise a IndexError by itself and
"blaming" it on list.pop?
class Stack(object):
def __init__(self, *items):
self.stack = list(items)
def push(self, item):
self.stack.append(item)
def pop(self):
try:
return self.stack.pop()
except:
raise IndexError, "pop from empty stack"
class Queue(object):
def __init__(self, *items):
self.queue = list(items)
def append(self, item):
self.queue.append(item)
def pop(self):
try:
return self.queue.pop(0)
except:
raise IndexError, "pop from empty queue"