From 4f9a5ee37b2024e7ba1a2d5002be179a9340e379 Mon Sep 17 00:00:00 2001 From: Jacques Garrigue Date: Tue, 21 Dec 1999 13:58:12 +0000 Subject: clean-up error handling code git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@2706 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02 --- otherlibs/labltk/browser/useunix.ml | 38 +++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'otherlibs/labltk/browser/useunix.ml') diff --git a/otherlibs/labltk/browser/useunix.ml b/otherlibs/labltk/browser/useunix.ml index f65f78c0d..9d29cc050 100644 --- a/otherlibs/labltk/browser/useunix.ml +++ b/otherlibs/labltk/browser/useunix.ml @@ -16,17 +16,21 @@ open Unix let get_files_in_directory dir = - try - let dirh = opendir dir in - let rec get_them () = - try - let x = readdir dirh in - x :: get_them () - with - _ -> closedir dirh; [] - in - Sort.list order:(<) (get_them ()) - with Unix_error _ -> [] + match + try Some(opendir dir) with Unix_error _ -> None + with + None -> [] + | Some dirh -> + let rec get_them l = + match + try Some(readdir dirh) with _ -> None + with + | Some x -> + get_them (x::l) + | None -> + closedir dirh; l + in + Sort.list order:(<=) (get_them []) let is_directory name = try @@ -39,11 +43,13 @@ let get_directories_in_files :path = (************************************************** Subshell call *) let subshell :cmd = let rc = open_process_in cmd in - let rec it () = - try - let x = input_line rc in x :: it () - with _ -> [] + let rec it l = + match + try Some(input_line rc) with _ -> None + with + Some x -> it (x::l) + | None -> List.rev l in - let answer = it () in + let answer = it [] in ignore (close_process_in rc); answer -- cgit v1.2.3-70-g09d2