From 16ab9644dd7421a7012c75302439d4819a169569 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Thu, 5 Feb 2015 22:15:43 +0600 Subject: Add some exceptions. --- src/vyconf_tree.ml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/vyconf_tree.ml b/src/vyconf_tree.ml index 449f095..f634d55 100644 --- a/src/vyconf_tree.ml +++ b/src/vyconf_tree.ml @@ -1,5 +1,9 @@ type 'a vyconf_tree = Node of string * 'a * ('a vyconf_tree list) +exception Empty_path +exception Duplicate_child +exception Nonexistent_path + let name_of_node (Node (name, _, _)) = name let children_of_node (Node (_, _, children)) = children @@ -47,14 +51,15 @@ let replace_child node child = let rec insert_child default_data node path data = match path with - | [] -> raise (Failure "Can't insert at empty path") + | [] -> raise Empty_path | [name] -> insert_immediate_child node name data | name :: names -> let next_child = find_child node name in match next_child with | Some next_child' -> let new_node = insert_child default_data next_child' names data in - replace_child node new_node + if names = [] then raise Duplicate_child + else replace_child node new_node | None -> let next_child' = Node (name, default_data, []) in let new_node = insert_child default_data next_child' names data in -- cgit v1.2.3