I'm playing with this: var n = 1; var d = 0;
union numeric_error = | overflow of string | divide_by_zero of int; type std_exception = "::std::exception"; fun msg: std_exception -> string = "$1.msg"; var r = try n/d catch numeric_error with | overflow ?s => -1 | divide_by_zero ?n => n catch std_exception with | ?x => #{ println$ "exception " + x.msg; throw x; return 0; } endtry ; The idea is basically to be able to catch a (C++) exception thrown by an expression and return an alternate value. Perhaps a better example: try fold_left (fun (acc, elt) => if elt == 0 then throw 0 else acc * elt) lst catch int with | ?i => i entry Basically, you can have a series of catch clauses, which catch particular types, and then pattern match the caught value and return some expression. This allows default values and shortcuts. The pattern match is an ordinary match on the caught exception. The match handlers must all return a value of the primary expression type (the type any should be allowed as well, so you can rethrow). It's a but clumsy to "do" something in an expression though. The syntax is related to functions: fun f: int -> string = | ?x => str x; which of course means: fun f(x:int) => str x; Another way to do this is match "catch" the same syntax as "fun", that is, any of the forms of fun. catch (x:int) => .... catch (x:long) => ... catch (x:std_exception) => .. The removes the need to put the match cases in as part of the syntax, however the return type, if specified on any of these functions, would have to equal the primary expression type, a bit redundant. Still thinking. Comments appreciated. Note: the try/entry is an expression. It has to return a consistent value (or not return normally). It can't be used by statements, because procedural code has no machine stack. -- john skaller skal...@users.sourceforge.net http://felix-lang.org ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language