我看到當 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