Why do exceptions take ints with try with?

why do we need the zero? Why is it of type int e.g.

let list_mult list =
try list_mult_aux list
(* with Zero -> Zero ;; *)
with Zero -> 0;;

Because your “with” branch must have the same type of the “tried” expression. Here, I suppose that list_mult_aux returns an integer?

1 Like


let rec list_mult_aux list =
match list with
| [] -> 1
| x::xs -> if x=0 then
raise Zero
x * list_mult_aux xs;;

but Im still confused…

Consider what the type of list_mult is. It can only have one type.