This compiles:
let inputFile = open_in("test.txt");
let line = try(input_line(inputFile)) {
| End_of_file => "end of file"
};
print_endline(line);
But not this:
let inputFile = open_in("test.txt");
try(input_line(inputFile)) {
| line => print_endline(line)
| exception End_of_file => print_endline("end of file")
};
For the latter I get an error: "Exception patterns must be at the top level of a match case"
I'm confused because it seems like an identical pattern to the one in the docs (https://reasonml.github.io/docs/en/exception.html)
let theItem = "a";
let myItems = ["b","a","c"];
switch (List.find((i) => i === theItem, myItems)) {
| item => print_endline(item)
| exception Not_found => print_endline("No such item found!")
};
Which compiles without error.
Changing the order of the match cases, or removing the "exception" keyword, doesn't change the error.
What does this error mean? I'm not sure what "top level" means.