def _evaluate_expression(frame, expression):
    """Helper function to evaluate expression in the context of input frame
    and throw error if evaluation failed. The evaluated SBValue is returned.
    """
    result_value = frame.EvaluateExpression(expression)
    if result_value is None or (
        result_value.GetError() and result_value.GetError().Fail()
    ):
        raise Exception(
            "Fail to evaluate {}: {}".format(
                expression, result_value.GetError().GetCString()
            )
        )
    return result_value