Skip to content

Commit c82c060

Browse files
authored
Add Try/Catch to Automation Script Solution Template (SkylineCommunications#18)
* Update $SCRIPTNAME$_1.cs Example try catch block inserted into template * Update $SCRIPTNAME$_1.cs Updated with suggestions from Thomas * Update $SCRIPTNAME$_1.cs A&O feedback updates: added just the ScriptTimeoutException catch as suggested and updated some of the comments
1 parent 013afcd commit c82c060

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

working/templates/automationsolution/$SCRIPTNAME$_1/$SCRIPTNAME$_1.cs

+35-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,40 @@ public class Script
1717
/// <param name="engine">Link with SLAutomation process.</param>
1818
public void Run(IEngine engine)
1919
{
20-
20+
try
21+
{
22+
RunSafe(engine);
23+
}
24+
catch (ScriptAbortException)
25+
{
26+
// catch normal abort exceptions (engine.ExitFail or engine.ExitSuccess)
27+
throw; // Comment if it should be treated as a normal exit of the script.
28+
}
29+
catch (ScriptForceAbortException)
30+
{
31+
// catch forced abort exceptions, caused via external maintenance messages
32+
throw;
33+
}
34+
catch (ScriptTimeoutException)
35+
{
36+
// catch timeout exceptions for when a script has been running for too long
37+
throw;
38+
}
39+
catch (InteractiveUserDetachedException)
40+
{
41+
// catch a user detaching from the interactive script by closing the window
42+
// only applicable for interactive scripts, can be removed for non-interactive scripts.
43+
throw;
44+
}
45+
catch (Exception e)
46+
{
47+
engine.ExitFail("Run|Something went wrong: " + e);
48+
}
49+
}
50+
51+
private void RunSafe(IEngine engine)
52+
{
53+
// TODO: Define code here
2154
}
2255
}
23-
}
56+
}

0 commit comments

Comments
 (0)