I have a quite simple issue I think, but no way to figure out what's going wrong. I want to open a file and try to failwith a custom message if the file don't exist or something else.
Here my code (sorry for french comment):
if (argc = 1) then
aide ()
else
(* Si plus d'un argument, on récupère le type *)
if argc >= 2 then
let stage = int_of_string (Sys.argv.(1)) in
if stage != 0 && stage != 1 then
aide ()
else
()
else
()
;
(* Si plus de deux arguments, on récupère aussi l'entrée *)
if argc >= 3 then
let filename = Sys.argv.(2) in
let input =
try
open_in filename
with _ -> failwith ("Impossible d'ouvrir le fichier " ^ filename)
else
()
;
;;
I've a syntax error on the with keyword. Someont have an idea ? Thanks.
The error occurred because you bound input to a value but did not return anything in the then branch.
You should do something with the value input and return () after the try/with block.
if argc >= 3 then
let filename = Sys.argv.(2) in
let input = (* The error is in this line *)
try
open_in filename
with _ -> failwith ("Impossible d'ouvrir le fichier " ^ filename)
else
()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With