add exception handling in parse_query