I am writing a command line tool in haxe (a mini lisp calculator :D) at this point of time in the project I cannot prevent the user to make an invalid call to a nonexisting function or use false arguments (it would require additional wrappers), so I though on the pythonic approach: let it crash and capture the error. However It seems I cannot catch in any way a C++ segmentation fault from haxe.
Example:
hxlisp => (+ 1 2)
REPL.hx:33: Null Function Pointer
hxlisp => (hello)
make: *** [cpp] Segmentation fault: 11
How does the code look like?
public function loop() {
while (true) {
try {
var inp:String = this.input();
if (inp.length == 0) continue;
var tree:SExpr = mkSexpr(parse(inp));
var a = SExpr.List(sexpr_values(tree)[0]);
var program = eval(a, env.std_env);
this.output(program);
} catch(eof:Eof) {
break;
} catch(error:Dynamic) {
trace(error);
}
}
}
However it seems there is no way (or I couldn't find it) to catch the error as exception and recover from it. Does anyone have an idea about how much is possible this approach of let it crash and recover from an error in HaxeC++? Note that in Neko or javascript that is not a problem.