Skip to content

Commit 3698de1

Browse files
BlakeSLCMichielOda
authored andcommitted
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 (cherry picked from commit c82c060)
1 parent d1bcf77 commit 3698de1

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
@@ -68,7 +68,40 @@ public class Script
6868
/// <param name="engine">Link with SLAutomation process.</param>
6969
public void Run(IEngine engine)
7070
{
71-
71+
try
72+
{
73+
RunSafe(engine);
74+
}
75+
catch (ScriptAbortException)
76+
{
77+
// catch normal abort exceptions (engine.ExitFail or engine.ExitSuccess)
78+
throw; // Comment if it should be treated as a normal exit of the script.
79+
}
80+
catch (ScriptForceAbortException)
81+
{
82+
// catch forced abort exceptions, caused via external maintenance messages
83+
throw;
84+
}
85+
catch (ScriptTimeoutException)
86+
{
87+
// catch timeout exceptions for when a script has been running for too long
88+
throw;
89+
}
90+
catch (InteractiveUserDetachedException)
91+
{
92+
// catch a user detaching from the interactive script by closing the window
93+
// only applicable for interactive scripts, can be removed for non-interactive scripts.
94+
throw;
95+
}
96+
catch (Exception e)
97+
{
98+
engine.ExitFail("Run|Something went wrong: " + e);
99+
}
100+
}
101+
102+
private void RunSafe(IEngine engine)
103+
{
104+
// TODO: Define code here
72105
}
73106
}
74-
}
107+
}

0 commit comments

Comments
 (0)