Commit 0064256e authored by bguillaum's avatar bguillaum

Simplification of exported exceptions

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/semagramme/libcaml-grew/trunk@9151 7838e531-6607-4d57-9587-6c381814729c
parent e01821e1
......@@ -279,7 +279,7 @@ module Grs = struct
(fun module_name ->
let modul =
try List.find (fun m -> m.Modul.name=module_name) grs.modules
with Not_found -> Log.fcritical "No module named '%s'" module_name in
with Not_found -> Error.build "No module named '%s'" module_name in
if modul.Modul.confluent
then Ast.Pick (Ast.Star (Ast.Ref module_name))
else Ast.Star (Ast.Ref module_name)
......@@ -298,7 +298,7 @@ module Grs = struct
with Not_found ->
let modul =
try List.find (fun m -> m.Modul.name=name) grs.modules
with Not_found -> Log.fcritical "No module or strategy named '%s'" name in
with Not_found -> Error.build "No module or strategy named '%s'" name in
Rule.conf_one_step ?domain: grs.domain name inst modul.Modul.rules
end
(* Union of strategies *)
......@@ -352,7 +352,7 @@ module Grs = struct
with Not_found ->
let modul =
try List.find (fun m -> m.Modul.name=name) grs.modules
with Not_found -> Log.fcritical "No module or strategy named '%s'" name in
with Not_found -> Error.build "No module or strategy named '%s'" name in
Rule.one_step ?domain: grs.domain name inst modul.Modul.rules
end
(* Union of strategies *)
......
......@@ -27,30 +27,27 @@ end
(* ==================================================================================================== *)
(** {2 Exceptions} *)
(* ==================================================================================================== *)
exception File_not_found of string
exception Parsing_err of string * Loc.t option
exception Build of string * Loc.t option
exception Run of string * Loc.t option
exception Bug of string * Loc.t option
exception Error of string
exception Bug of string
let handle ?(name="") ?(file="No file defined") fct () =
try fct () with
(* Raise again already caught exceptions *)
| Parsing_err (msg,loc_opt) -> raise (Parsing_err (msg,loc_opt))
| Build (msg,loc_opt) -> raise (Build (msg,loc_opt))
| Bug (msg, loc_opt) -> raise (Bug (msg,loc_opt))
| Run (msg, loc_opt) -> raise (Run (msg,loc_opt))
| File_not_found file -> raise (File_not_found file)
| Error msg -> raise (Error msg)
| Bug msg -> raise (Bug msg)
(* Catch new exceptions *)
| Grew_base.Error.Parse (msg, loc_opt) -> raise (Parsing_err (msg, loc_opt))
| Grew_base.Error.Build (msg, loc_opt) -> raise (Build (msg, loc_opt))
| Grew_base.Error.Bug (msg, loc_opt) -> raise (Bug (msg,loc_opt))
| Grew_base.Error.Run (msg, loc_opt) -> raise (Run (msg,loc_opt))
| Grew_base.Error.Parse (msg, Some loc) -> raise (Error (sprintf "%s %s" (Grew_base.Loc.to_string loc) msg))
| Grew_base.Error.Parse (msg, None) -> raise (Error (sprintf "%s" msg))
| Grew_base.Error.Build (msg, Some loc) -> raise (Error (sprintf "%s %s" (Grew_base.Loc.to_string loc) msg))
| Grew_base.Error.Build (msg, None) -> raise (Error (sprintf "%s" msg))
| Grew_base.Error.Run (msg, Some loc) -> raise (Error (sprintf "%s %s" (Grew_base.Loc.to_string loc) msg))
| Grew_base.Error.Run (msg, None) -> raise (Error (sprintf "%s" msg))
| Conll.Error msg -> raise (Error (sprintf "Conll error: %s" msg))
| Conll.Error msg -> raise (Parsing_err (msg,None))
| exc -> raise (Bug (sprintf "[Libgrew.%s] UNCAUGHT EXCEPTION: %s" name (Printexc.to_string exc), None))
| Grew_base.Error.Bug (msg, Some loc) -> raise (Bug (sprintf "%s %s" (Grew_base.Loc.to_string loc) msg))
| Grew_base.Error.Bug (msg, None) -> raise (Bug (sprintf "%s" msg))
| exc -> raise (Bug (sprintf "[Libgrew.%s] UNCAUGHT EXCEPTION: %s" name (Printexc.to_string exc)))
(* ==================================================================================================== *)
......@@ -106,7 +103,7 @@ type t = Grew_graph.G_graph.t
let load_gr ?domain file =
if not (Sys.file_exists file)
then raise (File_not_found file)
then raise (Error ("File_not_found: " ^ file))
else
handle ~name:"Graph.load_gr" ~file
(fun () ->
......@@ -129,7 +126,7 @@ type t = Grew_graph.G_graph.t
let load_pst ?domain file =
if not (Sys.file_exists file)
then raise (File_not_found file)
then raise (Error ("File_not_found: " ^ file))
else
handle ~name:"load_pst" ~file
(fun () ->
......@@ -220,7 +217,7 @@ module Grs = struct
handle ~name:"Grs.load" ~file
(fun () ->
if not (Sys.file_exists file)
then raise (File_not_found file)
then raise (Error ("File_not_found: " ^ file))
else Grew_grs.Grs.build file
) ()
......
......@@ -12,29 +12,12 @@ open Conll
val libgrew_debug_mode: unit -> unit
val get_version: unit -> string
(* ==================================================================================================== *)
(** {2 Location} *)
(* ==================================================================================================== *)
module Loc : sig
type t = Grew_base.Loc.t
val to_line: t -> int
val to_string: t -> string
end
(* ==================================================================================================== *)
(** {2 Exceptions} *)
(* ==================================================================================================== *)
exception File_not_found of string
exception Parsing_err of string * Loc.t option
(** raised when a Gr/Grs structure fails to build *)
exception Build of string * Loc.t option
(** raised during rewriting when a command is undefined *)
exception Run of string * Loc.t option
exception Bug of string * Loc.t option
exception Error of string
exception Bug of string
(* ==================================================================================================== *)
(** {2 Domain} *)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment