In the following code, I want to read a file and return all lines; if there is IO error, I want the program exit with error message print to console. But the program still run into unhandled exception. What’s the best practice for this? (I guess I dont need Some/None since I want to the program exit at error anyway.) thanks.
let lines =
try
IO.File.ReadAllLines("test.txt")
with
| ex -> failwithf " %s" ex.Message
You can do type test pattern matching.