Commits

Anonymous committed fe3f5ab

catching servers' exceptions

Comments (0)

Files changed (1)

     ;
 
 
+    value string_of_exn = Printexc.to_string
+    ;
+
+
     value (create_server :
       server_group 'i 'o ->
       server_dispatcher 'i 'o ->
         where rec server_loop msg =
           match msg with
           [ `Msg (arg, dest) ->
-              disp_ctx arg >>= fun res ->
-              dest_put dest (`Ok res) >>= fun () ->
+              IO.catch
+                (fun () -> disp_ctx arg >>= fun r -> IO.return (`Ok r))
+                (fun e -> IO.return (`Error (`Exn (string_of_exn e))))
+              >>= fun call_resp ->
+              dest_put dest call_resp >>= fun () ->
               ctx_for_proc#continue server_loop
           | `Cmd `Shutdown ->
               ctx_for_proc#exit