Hello, I’m trying to write an interpreter in ocaml and I’m using dune
to build the project. And I run into a problem about managing user-defined exceptions.
I declare all my exceptions in lib/exception.ml
, the file looks like this:
exception RuntimeError of string
exception InternalError of string
...
Then I wanna use these exceptions in another file lib/ast.ml
:
open Exception
let eval =
...
raise (RuntimeError "error")
...
However, dune build
gives me this error:
File "lib/ast.ml", line 1:
Error: The implementation lib/ast.pp.ml
does not match the interface lib/.tinyML.objs/byte/tinyML__Ast.cmi:
The exception `RuntimeError' is required but not provided
I can solve this error by rebind the exception: lib/ast.ml
open Exception
exception RuntimeError = Exception.RuntimeError
let eval =
...
raise (RuntimeError "error")
...
I wonder why I need to rebind exception to work, and whether there is a better way to manage exceptions.
Thanks!