我看到当 Parse JSON 在 Try 中失败时,catch 块似乎没有被执行。 我还发现,过去解析格式错误的 JSON 比这更成问题(请参阅这个线程),所以我从该线程中获取了建议的解析逻辑,这使我能够让 Try 按预期运行,但 Try 具有这种非常特定的场景,它不执行其捕获,这似乎是有问题的。
代码:
someVar = Try(
Parse JSON("{{1}}"),
Print("in catch 1");
2;
);
someVar2 = Try(
Throw( "broke!" ),
Print("in catch 2");
2;
);
someVar3 = Try(
txt = Log Capture( result = Parse JSON( "{{1}}") );
If( Length( txt ),
Throw( txt ) // error message
);
result; // parsed JSON
,
Print("in catch 3");
2;
);
Print("someVar is:");
Print(someVar);
Print("someVar2 is:");
Print(someVar2);
Print("someVar3 is:");
Print(someVar3);</CODE></P><P>输出:</P><P> </P><P> </P><PRE><CODE class=" language-jsl">Unexpected "{". Perhaps there is a missing }.
Line 1 Column 2: {►{1}}
"someVar is:"
.
"someVar2 is:"
2
"someVar3 is:"
2