def div(left, right): # TODO: division by zero to be tested try: result = left / right return result except ZeroDivisionError: DocumentDictionary.setProcessError(False) return None
def process(tree, nodeIndex): # security layer and domain out of bound handling try: if tree[Tree.leftChildIndex(nodeIndex)] != None: left = float(tree[Tree.leftChildIndex(nodeIndex)]) else: left = None if tree[Tree.rightChildIndex(nodeIndex)] != None: right = float(tree[Tree.rightChildIndex(nodeIndex)]) else: right = None parent = tree[nodeIndex] result = calculate(parent, left, right) tree[nodeIndex] = result Tree.removeChilds(tree, nodeIndex) except ValueError, e: if (e.message == "math domain error"): DocumentDictionary.setProcessError(False)