Quantcast
Channel: Active questions tagged ocaml - Stack Overflow
Viewing all articles
Browse latest Browse all 595

Exception Handling in OCaml

$
0
0

Say we have these two functions:

let divide_and_match x y =  match y with  | 0 -> raise (Failure "Division by zero")  | _ -> x / ylet divide_ten x y =  match x with   | 10 ->     let result = divide_and_match x y in     print_endline ("Result: " ^ string_of_int result)  | _ -> failwith "Bad"

I understand that if x was some input other than 10, "Bad" would get printed out, however I was curious about this:Would any error from divide_and_match x y besides the Failure "Division by zero" also result in "Bad" printed out?? Would divide_ten ever catch any errors from divide_and_match x y?

I was just confused on how exception handling works in match with cases i guess?


Viewing all articles
Browse latest Browse all 595

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>