故意引发 JSL 中的错误我一直在论坛和脚本索引中搜索执行此操作的方法,但没有找到任何可以完成我想做的事情。我正在寻找与 Python 的“Raise”函数具有类似功能的东西。或者与 Try Throw 语句本质上相同的功能,但不会引发 JSL 异常。
例如,我正在编写一个函数,要求用户以字符串的形式输入日期。为了防止错误,我想在函数中使用输入之前检查输入。
Example Function = Function({start_date,end_date},
chk1 = Is String(start_date);
If(chk1 == 0, //Raise some error here);
);我认为我可以通过 Show("Error message") 和 Break() 序列完成我想要的任务,但我想知道是否有任何本机 JSL 方法可以完成此任务。
回复:在 JSL 中故意引发错误您可以使用 Throw 来引发错误。在捕获用户输入错误的上下文中,您可以使用带有 OnValidate 消息的模式窗口:
NewWindow("Demo", <<MODAL></MODAL>
回复:在 JSL 中故意引发错误我使用模态窗口的组合来为用户提供错误消息,并抛出异常来终止执行。
Example Date Check = Function({start_date,end_date},
chk1 = Is String(start_date);
If (!chk1 == 0,
emsg = "Invalid start date [" || char(start_date) || "]";
ew = new window("Invalid date", << modal(),
text box(emsg),
);
throw(emsg);
);
chk2 = Is String(end_date);
If (!chk2 == 0,
emsg = "Invalid end date [" || char(end_date) || "]";
ew = new window("Invalid date", << modal(),
text box(emsg),
);
throw(emsg);
);
);
example date check(today(), today());
example date check("31-Feb-2018", today());回复:在 JSL 中故意引发错误您可以使用扔()无需尝试。 我认为它类似于Python中的Raise()。
//:*/
show("Here");
throw("This didn't work");
show("Here 2");
/*:
"Here";
This didn't work
回复:在 JSL 中故意引发错误使用 Try() 函数,然后检查它的结果