【发布时间】:2012-12-18 06:16:19
【问题描述】:
我正在尝试添加在抛出异常后捕获异常的机制 以前在代码中,但我无法编译:
这是没有异常处理的代码 - 它编译和工作得很好:
fun calc(input : string ) : int =
let
val outStr = ref "someString"
val outInt = ref 0
in
(
outStr := replaceRomanDec(input); (* replace roman number with decimal *)
outInt := calcMyRomanExpression(!outStr)
);
(!outInt)
end;
但是当我尝试把 handle 和 exception 放在这里时:
fun calc(input : string ) : int =
exception CalculatorParser
let
val outStr = ref "someString"
val outInt = ref 0
in
(
outStr := replaceRomanDec(input); (* replace roman number with decimal *)
outInt := calcMyRomanExpression(!outStr);
handle CalculatorParser => -1
);
(!outInt)
end;
我明白了:
stdIn:1761.2-1761.28 Error: syntax error: deleting EXCEPTION ID
- );
=
= (!outInt)
=
=
=
= end;
stdIn:1576.1-1757.2 Error: syntax error: deleting RPAREN SEMICOLON
-
我尝试按照错误中的建议添加/删除分号,但没有任何效果。
知道有什么问题吗?
亲切的问候
【问题讨论】:
-
我强烈建议您不要使用引用。使用它们不会带来任何好处,而且你会失去进行函数式编程的全部意义!