在大型 JSL 專案中,使用 Include() 呼叫進行錯誤處理的最佳實務是什麼?I'm working on a large JSL project that uses many Include() calls to organize the code. I've run into an issue where if one of the included scripts fails, the main script continues executing, which can lead to cascading errors or unexpected behavior.
目前,我正在考慮重構我的包含檔案結構,使其僅包含函數定義而非可執行程式碼。這樣做的目的是,如果某個包含檔案在定義階段失敗,後續對這些函數的呼叫將會更明確地失敗。
不過,我想知道是否有更好的方法來處理這種情況。具體來說:
- Is there a way to make
Include() halt execution if the included script encounters an error?
- 將函數定義與可執行程式碼分離是否是建議的做法,或者對於大型 JSL 專案是否有其他更合適的架構模式?
我想了解其他人是如何建立 JSL 專案以穩健地處理依賴項的。
自動化和腳本編寫回覆:在大型 JSL 專案中使用 Include() 呼叫時,錯誤處理的最佳實務是什麼?我認為一種方法是用 Try() 函數包裹你的 include 語句。
test1.jsl
Names Default To Here(1);
show
test2.jsl
Names Default To Here(1);
Try(
Include("test1.jsl");
,
Throw(Char(exception_msg));
);<BR /><BR />Show("not executed");<BR />