Commit ec692865 authored by Taddeus Kroes's avatar Taddeus Kroes

funclang series2: Added error messages to exceptions.

parent 01680d11
...@@ -17,7 +17,7 @@ test_isLeapYear 1904 true;; ...@@ -17,7 +17,7 @@ test_isLeapYear 1904 true;;
(* Give a proper English character string representation of a date *) (* Give a proper English character string representation of a date *)
let date2str day month year = let date2str day month year =
if day < 1 || day > 31 || month < 1 || month > 12 || year < 0 then if day < 1 || day > 31 || month < 1 || month > 12 || year < 0 then
raise Exit raise (Failure "invalid date")
else else
(* Get the textual postfix of a day number *) (* Get the textual postfix of a day number *)
let getDayPostfix day = let getDayPostfix day =
...@@ -45,7 +45,7 @@ test_date2str 9 2 2010 "February 9th, 2010";; ...@@ -45,7 +45,7 @@ test_date2str 9 2 2010 "February 9th, 2010";;
(* Sum all digits of a natural number *) (* Sum all digits of a natural number *)
let rec sum_digits n = let rec sum_digits n =
if n < 0 then raise Exit else if n < 0 then raise (Failure "cannot sum digits in integers below 0") else
let str = string_of_int n in let str = string_of_int n in
let l = String.length str in let l = String.length str in
if l = 1 then if l = 1 then
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment