Exception handling 尝试对Unix_错误(Ocaml)进行模式匹配时出错?

Exception handling 尝试对Unix_错误(Ocaml)进行模式匹配时出错?,exception-handling,compiler-errors,pattern-matching,ocaml,utop,Exception Handling,Compiler Errors,Pattern Matching,Ocaml,Utop,我一直在尝试为用户在无效目录中键入的情况设置模式: # let dir = Unix.opendir "adfalf";; Exception: Unix.Unix_error (Unix.ENOENT, "opendir", "adfalf"). 我的职能如下: let files_of_dir d = try let dir = Unix.opendir d in ... with Unix_error (uerr, ucomma

我一直在尝试为用户在无效目录中键入的情况设置模式:

# let dir = Unix.opendir "adfalf";;
Exception: Unix.Unix_error (Unix.ENOENT, "opendir", "adfalf"). 
我的职能如下:

let files_of_dir d = 
    try 
      let dir = Unix.opendir d in
      ...
    with
       Unix_error (uerr, ucommand, dir) -> raise Not_found
除非我一直得到编译错误:

Error: This variant pattern is expected to have type exn
       The constructor Unix_error does not belong to type exn
我不明白我做错了什么,模式匹配。如果有人能在这方面帮助我,我将不胜感激


一些其他注释:

我一直在终端上使用以下命令编译代码:

ocamlbuild filename.byte

您需要说
Unix.Unix\u error
,而不仅仅是
Unix\u error
。请注意,这是示例会话中显示的内容