我试图在之前在代码中抛出异常后添加捕获异常的机制,但我无法编译它:
这是没有异常处理的代码 - 它编译并且工作得很好:
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
and放在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
-
我尝试按照错误中的建议添加/删除分号,但没有任何效果。
知道有什么问题吗?
亲切的问候