(* Adrian Pop, adrpo@ida.liu.se, http://www.ida.liu.se/~adrpo *) (* 2005-01-15 *) (* problem with exceptions in SML.NET version: SML.NET 1.2 build 1102 of Friday, 07 January 2005 Running on .NET Framework v1.1.4322 Using assembler in C:\bin\sml.net\bin\v1.1.4322\ilasm.exe Using class list tool in C:\bin\sml.net\bin\v1.1.4322\clslist.exe Using metadata import tool in C:\bin\sml.net\bin\v1.1.4322\getmeta.exe http://www.cl.cam.ac.uk/Research/TSG/SMLNET/ *) (* Problem description: - exception is ignored in Release version even thou' it should be raised + compile in Release and run the exe, it will exit without any problem - exception works in Debug version + compile in Debug and run the exe, it will raise an error Output: adrpo@kafka /cygdrive/c/dev/sml.net.error/RML $ Release/RML.exe unifying: string ?=? string the types can be unified adrpo@kafka /cygdrive/c/dev/sml.net.error/RML $ Debug/RML.exe unifying: string ?=? string does not unify! static elaboration error! *) structure RML : sig val main: unit -> unit end = struct type ty = string datatype tyerr_explanation = TY_ERROR of ty * string | TY_DIFFER of ty * ty * string exception TypeError of tyerr_explanation fun tyErrDiffer(ty1, ty2, why) = (* this doesn't do raise in Release, if you put a print "raised" before it works *) raise TypeError(TY_DIFFER(ty1, ty2, why)) fun unify(ty1, ty2) = (ty1 = ty2) fun unify_list(tys1, tys2, ty1, ty2) = let fun loop([], []) = (print "\nunifying: [] ?=? []\n"; ()) | loop(ty1::tys1, ty2::tys2) = (print "\nunifying: "; print ty1; print " ?=? "; print ty2; print "\n"; unify(ty1, ty2); (* here it will be loop("list",nil) which should trigger the last case in the loop *) loop(tys1, tys2)) (* this is actually "called" in the Release version but doesn't raise *) (* in Debug version it does the raise *) (* this doesn't do raise in Release, BUT you put a print "before raise" before it works *) | loop(_, _) = tyErrDiffer(ty1, ty2, " arity ") in loop(tys1, tys2) end exception StaticElaborationError fun elab(exp_taus, pat_taus) = let val _ = unify_list(exp_taus, pat_taus, "", "") handle exn => ((case exn of TypeError explain => print "does not unify!\n" | StaticElaborationError => () | _ => print "other problems\n"); raise StaticElaborationError) in (print " the types can be unified ") end fun main () = let val argz = CommandLine.arguments() val _ = elab(["string","list"],["string"]) (* unify these: SHOULDN'T WORK!! for the second *) handle exn => (case exn of StaticElaborationError => (print "static elaboration error!") | _ => print "Other exception!") in () handle exn => print ("\nException raised during compilation :" ^ exnMessage exn; OS.Process.exit 0) end end